BBC BASIC for Windows
Programming >> Communication and Input/Output >> COM Lighting Control.
http://bb4w.conforums.com/index.cgi?board=communication&action=display&num=1282607753

COM Lighting Control.
Post by thefamouscash on Aug 23rd, 2010, 11:55pm

I have programmed in BBC Basic since first on market and can usually get it to do what I want. I have written a prog for snooker halls which is successful but need to control each table light ON/OFF through COM port.
I have purchased a UDIN-8R device which will control 8 switches to experiment but cannot see how it works. (No CD or instructions).

I understand all I need to do is pass ascii codes through the USB. Not getting anywhere.

I cannot get the advice under Modem control input/output help to work. Any assistance, please?
Re: COM Lighting Control.
Post by admin on Aug 24th, 2010, 08:13am

on Aug 23rd, 2010, 11:55pm, thefamouscash wrote:
I have purchased a UDIN-8R device which will control 8 switches to experiment but cannot see how it works. (No CD or instructions).

Google found me this: http://www.audon.co.uk/udin.html

It would appear that you can drive it either as a virtual COM port or using direct DLL calls, both of which should be straightforward from BB4W. Various software drivers and examples are available for download from that site.

Richard.
Re: COM Lighting Control.
Post by thefamouscash on Aug 24th, 2010, 12:56pm

Thank you for your response.
Beyond me still at the moment.
Guess I will just have to keep experimenting.
Regards.
Re: COM Lighting Control.
Post by admin on Aug 24th, 2010, 1:03pm

on Aug 24th, 2010, 12:56pm, thefamouscash wrote:
Beyond me still at the moment.

There are many examples of accessing external devices via DLL calls that you can find in the various sources of BB4W code. It should be a relatively simple matter of adapting one of those (e.g. the K8055D drivers would be a good starting point). So long as you have the DLL itself, its documentation and code examples in, say, Visual Basic or C it should be plain sailing.

Richard.

Re: COM Lighting Control.
Post by thefamouscash on Aug 25th, 2010, 12:11pm

I really am trying but it's all too much for me. Is there no way to spell it out for me? According to the manual I just need to send "N1" to a port to switch on relay 1. I have tried using all code I could fing in "Help" (Set RTS et cetera) in association but no success. Just can't get basic understanding of process.
Re: COM Lighting Control.
Post by admin on Aug 25th, 2010, 1:17pm

on Aug 25th, 2010, 12:11pm, thefamouscash wrote:
According to the manual I just need to send "N1" to a port to switch on relay 1.

That's presumably using the 'virtual COM port' method. Personally I would prefer to use the DLL method instead, because it seems more straightforward and gives a more 'direct' communication path than going through a serial data channel that doesn't really exist.

Quote:
Is there no way to spell it out for me?

Richard.
Re: COM Lighting Control.
Post by thefamouscash on Aug 25th, 2010, 1:22pm

Thank you once again.
If I can find the "DLL" (Once I find out what it is!) I will try to follow your advice.
Re: COM Lighting Control.
Post by thefamouscash on Aug 25th, 2010, 10:37pm

Hi Richard,
Thanks for all your help to date. I've been working through your suggestions with some (!) success.
Have the DLL implemented and being accessed through Basic CODE:
<SNIPPET>
SYS "LoadLibrary", "ftd2xx.dll" TO virtpor0%
</SNIPPET>

Have confirmed that this is being read in:
<SNIPPET>
IF virtpor0% = 0 ERROR 100, "Cannot load DLL0"
</SNIPPET>

However....don't seem to be successfully making calls to the dll functions. I have some VB and .NET code however I'm not able to successfully manually convert this to BASIC code that is working. You note in your previous post that there is a VB2BBC application - I've googled unsuccessfully for this - are you able to provide a link/copy etc. Failing that can I post a more extensive code snippet - sure it is something obvious that I'm just missing.

Many thanks again.


Re: COM Lighting Control.
Post by admin on Aug 26th, 2010, 09:49am

on Aug 25th, 2010, 10:37pm, thefamouscash wrote:
You note in your previous post that there is a VB2BBC application - I've googled unsuccessfully for this

Because of its somewhat 'experimental' nature there's a closed user group for the VB2BBC application, which you would be welcome to join. See for example this message on the discussion group: http://tech.groups.yahoo.com/group/bb4w/message/13029

Quote:
Failing that can I post a more extensive code snippet

That's what I suggest you do. Unlike the discussion group, where posting significant amounts of code is discouraged, it's OK to do so here (remember to use 'code' tags so it is properly displayed and formatted).

Richard.
Re: COM Lighting Control.
Post by thefamouscash on Aug 27th, 2010, 01:02am

Richard,
Trying to follow your advice within my limited knowledge.
I trust I am not contravening law by copying the sample below.
Hope this is what is required.
Bob.

Example – How to program the device
The following Visual Basic uses the FTDI DLL to directly interface the hardware.
Public Class AudonUSB
Private Sub SetUSB_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles SetUSB.Click
Dim BytesWritten As Integer
Dim TempStringData As String
Dim BytesRead As Integer
'Open device by serial number
FT_Status = FT_OpenBySerialNumber(FT_Serial_Number, 1,
FT_Handle)
If FT_Status <> FT_OK Then
MsgBox("Failed to open device.", , )
Exit Sub
End If
' Reset device
FT_Status = FT_ResetDevice(FT_Handle)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Purge buffers
FT_Status = FT_Purge(FT_Handle, FT_PURGE_RX Or FT_PURGE_TX)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Set Baud Rate
FT_Status = FT_SetBaudRate(FT_Handle, 9600)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Set parameters
FT_Status = FT_SetDataCharacteristics(FT_Handle,
FT_DATA_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Set Flow Control
FT_Status = FT_SetFlowControl(FT_Handle, FT_FLOW_NONE, 0, 0)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Display in a message box all the items that are checked.
Dim indexChecked As Integer
Dim iRelays As Integer = 0
' First show the index and check state of all selected items.
For Each indexChecked In SetBits.CheckedIndices
iRelays = iRelays + 2 ^ Val(indexChecked.ToString())
Next
' Write string data to device
Dim sOutput As String
'If iRelays < 16 Then
'sOutput = "r0" + Hex(iRelays) + Chr(13)
'Else
'sOutput = "r" + Hex(iRelays) + Chr(13)
'End If
'sOutput = Me.TextBox1.Text + Chr(13)
sOutput = "r" + Trim(Str(iRelays)) + Chr(13)
FT_Status = FT_Write_String(FT_Handle, sOutput, Len(sOutput),
BytesWritten)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Wait
Sleep(100)
' Get number of bytes waiting to be read
FT_Status = FT_GetQueueStatus(FT_Handle, FT_RxQ_Bytes)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Read number of bytes waiting
' Allocate string to recieve data
TempStringData = Space(FT_RxQ_Bytes + 1)
FT_Status = FT_Read_String(FT_Handle, TempStringData,
FT_RxQ_Bytes, BytesRead)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Close device
FT_Status = FT_Close(FT_Handle)
If FT_Status <> FT_OK Then
Exit Sub
End If
End Sub
Private Sub AudonUSB_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
Dim DeviceCount As Integer
Dim DeviceIndex As Integer
Dim TempDevString As String
' Get the number of device attached
FT_Status = FT_GetNumberOfDevices(DeviceCount, vbNullChar,
FT_LIST_NUMBER_ONLY)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Exit if no device connected
If DeviceCount = 0 Then
MsgBox("No Device Connected", MsgBoxStyle.Critical)
Exit Sub
End If
' Clear device list
DeviceList.Items.Clear()
' List devices in dropdown
For DeviceIndex = 0 To DeviceCount - 1
' Get serial number of device with index 0
' Allocate space for string variable
TempDevString = Space(16)
FT_Status = FT_GetDeviceString(DeviceIndex,
TempDevString, FT_LIST_BY_INDEX Or FT_OPEN_BY_SERIAL_NUMBER)
If FT_Status <> FT_OK Then
Exit Sub
End If
FT_Serial_Number =
Microsoft.VisualBasic.Left(TempDevString, InStr(1, TempDevString,
vbNullChar) - 1)
' Get description of device with index 0
' Allocate space for string variable
TempDevString = Space(64)
FT_Status = FT_GetDeviceString(DeviceIndex,
TempDevString, FT_LIST_BY_INDEX Or FT_OPEN_BY_DESCRIPTION)
If FT_Status <> FT_OK Then
Exit Sub
End If
FT_Description =
Microsoft.VisualBasic.Left(TempDevString, InStr(1, TempDevString,
vbNullChar) - 1)
' Add to dropdown
DeviceList.Items.Add(FT_Description + " " +
FT_Serial_Number)
Next
' Set first device
DeviceList.SelectedIndex = 0
End Sub
Private Sub DeviceList_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DeviceList.SelectedIndexChanged
Dim sDevice As String
Dim iSpace As Integer
sDevice =
DeviceList.Items.Item(DeviceList.SelectedIndex).ToString
iSpace = InStrRev(sDevice, " ")
If iSpace > 0 Then
FT_Description = Trim(Microsoft.VisualBasic.Left(sDevice,
iSpace - 1))
FT_Serial_Number =
Trim(Microsoft.VisualBasic.Mid(sDevice, iSpace + 1))
End If
End Sub
Private Sub ReadUSB_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles ReadUSB.Click
Dim BytesWritten As Integer
Dim TempStringData As String
Dim BytesRead As Integer
'Open device by serial number
FT_Status = FT_OpenBySerialNumber(FT_Serial_Number, 1,
FT_Handle)
If FT_Status <> FT_OK Then
MsgBox("Failed to open device.", , )
Exit Sub
End If
' Reset device
FT_Status = FT_ResetDevice(FT_Handle)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Purge buffers
FT_Status = FT_Purge(FT_Handle, FT_PURGE_RX Or FT_PURGE_TX)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Set Baud Rate
FT_Status = FT_SetBaudRate(FT_Handle, 9600)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Set parameters
FT_Status = FT_SetDataCharacteristics(FT_Handle,
FT_DATA_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Set Flow Control
FT_Status = FT_SetFlowControl(FT_Handle, FT_FLOW_NONE, 0, 0)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Write string data to device
Dim sOutput As String
If ReadInputs.Checked = True Then
' Read inputs
sOutput = "i0" + Chr(13)
Else
' Relay Status
sOutput = "s0" + Chr(13)
End If
FT_Status = FT_Write_String(FT_Handle, sOutput, Len(sOutput),
BytesWritten)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Wait
Sleep(100)
' Get number of bytes waiting to be read
FT_Status = FT_GetQueueStatus(FT_Handle, FT_RxQ_Bytes)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Read number of bytes waiting
' Allocate string to recieve data
TempStringData = Space(FT_RxQ_Bytes + 1)
FT_Status = FT_Read_String(FT_Handle, TempStringData,
FT_RxQ_Bytes, BytesRead)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Change LED color depending on input
Dim iInput As Integer
TempStringData = Replace(TempStringData, "i0", " ")
TempStringData = Replace(TempStringData, "s0", " ")
TempStringData = Replace(TempStringData, Chr(13), " ")
TempStringData = Trim(Replace(TempStringData, Chr(10), " "))
iInput = Val(TempStringData)
If (iInput And 1) Then
LED0.BackColor = Color.LightGreen
Else
LED0.BackColor = Color.DarkGreen
End If
If (iInput And 2) Then
LED1.BackColor = Color.LightGreen
Else
LED1.BackColor = Color.DarkGreen
End If
If (iInput And 4) Then
LED2.BackColor = Color.LightGreen
Else
LED2.BackColor = Color.DarkGreen
End If
If (iInput And 8) Then
LED3.BackColor = Color.LightGreen
Else
LED3.BackColor = Color.DarkGreen
End If
If (iInput And 16) Then
LED4.BackColor = Color.LightGreen
Else
LED4.BackColor = Color.DarkGreen
End If
If (iInput And 32) Then
LED5.BackColor = Color.LightGreen
Else
LED5.BackColor = Color.DarkGreen
End If
If (iInput And 64) Then
LED6.BackColor = Color.LightGreen
Else
LED6.BackColor = Color.DarkGreen
End If
If (iInput And 128) Then
LED7.BackColor = Color.LightGreen
Else
LED7.BackColor = Color.DarkGreen
End If
' Close device
FT_Status = FT_Close(FT_Handle)
If FT_Status <> FT_OK Then
Exit Sub
End If
End Sub
End Class
Re: COM Lighting Control.
Post by admin on Aug 27th, 2010, 09:05am

on Aug 27th, 2010, 01:02am, thefamouscash wrote:
Hope this is what is required.

I asked you to use code tags to ensure that your listing was correctly formatted, yet you didn't do so. As a result many of the lines have 'wrapped', and indentation has been lost, making it much harder to read and interpret the code. Please make full use of the facilities of this board, such as being able to embed code within messages, so that people can help you more easily.

I'll get back to you when I've managed to unscramble the code you listed.

Richard.

Re: COM Lighting Control.
Post by admin on Aug 27th, 2010, 09:36am

I've managed to convert the code into BBC BASIC, with the help of VB2BBC, but really it's so massively overcomplicated for what you want to achieve it seems ridiculous.

Maybe using the virtual COM port interface would be easier after all. Please list any example code provided for that mode of operation. And don't forget those code tags!

Richard.
Re: COM Lighting Control.
Post by thefamouscash on Aug 27th, 2010, 09:58am

I will try to obtain that code.
I noticed someone else had mentioned VB2BBC so I sent a direct email requesting a link for VB2BBC and still feel this may be of use. The code I attempted to give is (I believe) the entire code for communicating with the unit.
Sorry for inconvenience, I do not know how add code tags but will find out.
Bob.
Re: COM Lighting Control.
Post by admin on Aug 27th, 2010, 10:31am

on Aug 27th, 2010, 09:58am, thefamouscash wrote:
I noticed someone else had mentioned VB2BBC so I sent a direct email requesting a link for VB2BBC and still feel this may be of use.

You were sent the 'Welcome to the VB2BBC user group' email yesterday, containing the download link. However your code caused VB2BBC to crash, therefore I had to modify it to produce any usable results. That's the trouble with experimental software!

I've had very little feedback from members of the VB2BBC User Group (I think none) so I am not motivated to put much effort into an application in which so few people seem to have any interest.

Quote:
I do not know how add code tags

Do you not see Add tags: when you are entering your message? The 'insert code' tag is the one with a # symbol.

Richard.
Re: COM Lighting Control.
Post by thefamouscash on Aug 27th, 2010, 2:03pm

Apologies that my lack of skill is causing undue effort. I now see the # to insert code and will use that if I can find suitable code.
I regret I do not appear to have received the welcome to BV2BBC email. Is it possible to resend?
I believe I may be able to translate a piece at a time and find relevant sections.

With thanks,

Bob.
Re: COM Lighting Control.
Post by admin on Aug 27th, 2010, 4:05pm

on Aug 27th, 2010, 2:03pm, thefamouscash wrote:
I regret I do not appear to have received the welcome to BV2BBC email. Is it possible to resend?

OK, I've sent it again. Do note that your VB code is likely to crash VB2BBC (v0.06), so I apologise for any frustration this may cause.

Richard.

Re: COM Lighting Control.
Post by thefamouscash on Aug 27th, 2010, 4:19pm

I cannot trace the alternative code at the moment and note you were going to try to read the corrupted data I sent.
In order to save some effort, I have re-tried to send correctly below.
Code:
TEXT 

UDIN - USB Relay / Digital Input, Output Example
To set a Relay / Digital Output, check the appropriate box and click the Set button.
To read a Digital Input, choose Read Inputs and click the Read button.
To read a Relay Status, choose Relay Status and click the Read button.
Visual Basic Example – How to program the device
The following Visual Basic uses the FTDI DLL to directly interface the hardware.
Public Class AudonUSB
Private Sub SetUSB_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles SetUSB.Click
Dim BytesWritten As Integer
Dim TempStringData As String
Dim BytesRead As Integer
'Open device by serial number
FT_Status = FT_OpenBySerialNumber(FT_Serial_Number, 1,
FT_Handle)
If FT_Status <> FT_OK Then
MsgBox("Failed to open device.", , )
Exit Sub
End If
' Reset device
FT_Status = FT_ResetDevice(FT_Handle)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Purge buffers
FT_Status = FT_Purge(FT_Handle, FT_PURGE_RX Or FT_PURGE_TX)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Set Baud Rate
FT_Status = FT_SetBaudRate(FT_Handle, 9600)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Set parameters
FT_Status = FT_SetDataCharacteristics(FT_Handle,
FT_DATA_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Set Flow Control
FT_Status = FT_SetFlowControl(FT_Handle, FT_FLOW_NONE, 0, 0)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Display in a message box all the items that are checked.
Dim indexChecked As Integer
Dim iRelays As Integer = 0
' First show the index and check state of all selected items.
For Each indexChecked In SetBits.CheckedIndices
iRelays = iRelays + 2 ^ Val(indexChecked.ToString())
Next
' Write string data to device
Dim sOutput As String
'If iRelays < 16 Then
'sOutput = "r0" + Hex(iRelays) + Chr(13)
'Else
'sOutput = "r" + Hex(iRelays) + Chr(13)
'End If
'sOutput = Me.TextBox1.Text + Chr(13)
sOutput = "r" + Trim(Str(iRelays)) + Chr(13)
FT_Status = FT_Write_String(FT_Handle, sOutput, Len(sOutput),
BytesWritten)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Wait
Sleep(100)
' Get number of bytes waiting to be read
FT_Status = FT_GetQueueStatus(FT_Handle, FT_RxQ_Bytes)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Read number of bytes waiting
' Allocate string to recieve data
TempStringData = Space(FT_RxQ_Bytes + 1)
FT_Status = FT_Read_String(FT_Handle, TempStringData,
FT_RxQ_Bytes, BytesRead)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Close device
FT_Status = FT_Close(FT_Handle)
If FT_Status <> FT_OK Then
Exit Sub
End If
End Sub
Private Sub AudonUSB_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
Dim DeviceCount As Integer
Dim DeviceIndex As Integer
Dim TempDevString As String
' Get the number of device attached
FT_Status = FT_GetNumberOfDevices(DeviceCount, vbNullChar,
FT_LIST_NUMBER_ONLY)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Exit if no device connected
If DeviceCount = 0 Then
MsgBox("No Device Connected", MsgBoxStyle.Critical)
Exit Sub
End If
' Clear device list
DeviceList.Items.Clear()
' List devices in dropdown
For DeviceIndex = 0 To DeviceCount - 1
' Get serial number of device with index 0
' Allocate space for string variable
TempDevString = Space(16)
FT_Status = FT_GetDeviceString(DeviceIndex,
TempDevString, FT_LIST_BY_INDEX Or FT_OPEN_BY_SERIAL_NUMBER)
If FT_Status <> FT_OK Then
Exit Sub
End If
FT_Serial_Number =
Microsoft.VisualBasic.Left(TempDevString, InStr(1, TempDevString,
vbNullChar) - 1)
' Get description of device with index 0
' Allocate space for string variable
TempDevString = Space(64)
FT_Status = FT_GetDeviceString(DeviceIndex,
TempDevString, FT_LIST_BY_INDEX Or FT_OPEN_BY_DESCRIPTION)
If FT_Status <> FT_OK Then
Exit Sub
End If
FT_Description =
Microsoft.VisualBasic.Left(TempDevString, InStr(1, TempDevString,
vbNullChar) - 1)
' Add to dropdown
DeviceList.Items.Add(FT_Description + " " +
FT_Serial_Number)
Next
' Set first device
DeviceList.SelectedIndex = 0
End Sub
Private Sub DeviceList_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DeviceList.SelectedIndexChanged
Dim sDevice As String
Dim iSpace As Integer
sDevice =
DeviceList.Items.Item(DeviceList.SelectedIndex).ToString
iSpace = InStrRev(sDevice, " ")
If iSpace > 0 Then
FT_Description = Trim(Microsoft.VisualBasic.Left(sDevice,
iSpace - 1))
FT_Serial_Number =
Trim(Microsoft.VisualBasic.Mid(sDevice, iSpace + 1))
End If
End Sub
Private Sub ReadUSB_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles ReadUSB.Click
Dim BytesWritten As Integer
Dim TempStringData As String
Dim BytesRead As Integer
'Open device by serial number
FT_Status = FT_OpenBySerialNumber(FT_Serial_Number, 1,
FT_Handle)
If FT_Status <> FT_OK Then
MsgBox("Failed to open device.", , )
Exit Sub
End If
' Reset device
FT_Status = FT_ResetDevice(FT_Handle)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Purge buffers
FT_Status = FT_Purge(FT_Handle, FT_PURGE_RX Or FT_PURGE_TX)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Set Baud Rate
FT_Status = FT_SetBaudRate(FT_Handle, 9600)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Set parameters
FT_Status = FT_SetDataCharacteristics(FT_Handle,
FT_DATA_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Set Flow Control
FT_Status = FT_SetFlowControl(FT_Handle, FT_FLOW_NONE, 0, 0)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Write string data to device
Dim sOutput As String
If ReadInputs.Checked = True Then
' Read inputs
sOutput = "i0" + Chr(13)
Else
' Relay Status
sOutput = "s0" + Chr(13)
End If
FT_Status = FT_Write_String(FT_Handle, sOutput, Len(sOutput),
BytesWritten)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Wait
Sleep(100)
' Get number of bytes waiting to be read
FT_Status = FT_GetQueueStatus(FT_Handle, FT_RxQ_Bytes)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Read number of bytes waiting
' Allocate string to recieve data
TempStringData = Space(FT_RxQ_Bytes + 1)
FT_Status = FT_Read_String(FT_Handle, TempStringData,
FT_RxQ_Bytes, BytesRead)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Change LED color depending on input
Dim iInput As Integer
TempStringData = Replace(TempStringData, "i0", " ")
TempStringData = Replace(TempStringData, "s0", " ")
TempStringData = Replace(TempStringData, Chr(13), " ")
TempStringData = Trim(Replace(TempStringData, Chr(10), " "))
iInput = Val(TempStringData)
If (iInput And 1) Then
LED0.BackColor = Color.LightGreen
Else
LED0.BackColor = Color.DarkGreen
End If
If (iInput And 2) Then
LED1.BackColor = Color.LightGreen
Else
LED1.BackColor = Color.DarkGreen
End If
If (iInput And 4) Then
LED2.BackColor = Color.LightGreen
Else
LED2.BackColor = Color.DarkGreen
End If
If (iInput And 8) Then
LED3.BackColor = Color.LightGreen
Else
LED3.BackColor = Color.DarkGreen
End If
If (iInput And 16) Then
LED4.BackColor = Color.LightGreen
Else
LED4.BackColor = Color.DarkGreen
End If
If (iInput And 32) Then
LED5.BackColor = Color.LightGreen
Else
LED5.BackColor = Color.DarkGreen
End If
If (iInput And 64) Then
LED6.BackColor = Color.LightGreen
Else
LED6.BackColor = Color.DarkGreen
End If
If (iInput And 128) Then
LED7.BackColor = Color.LightGreen
Else
LED7.BackColor = Color.DarkGreen
End If
' Close device
FT_Status = FT_Close(FT_Handle)
If FT_Status <> FT_OK Then
Exit Sub
End If
End Sub
End Class
Code:
TEXT 


I hope this is correct.
Bob.
Re: COM Lighting Control.
Post by thefamouscash on Aug 27th, 2010, 4:25pm

Code:


Public Class AudonUSB
Private Sub SetUSB_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles SetUSB.Click
Dim BytesWritten As Integer
Dim TempStringData As String
Dim BytesRead As Integer
'Open device by serial number
FT_Status = FT_OpenBySerialNumber(FT_Serial_Number, 1,
FT_Handle)
If FT_Status <> FT_OK Then
MsgBox("Failed to open device.", , )
Exit Sub
End If
' Reset device
FT_Status = FT_ResetDevice(FT_Handle)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Purge buffers
FT_Status = FT_Purge(FT_Handle, FT_PURGE_RX Or FT_PURGE_TX)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Set Baud Rate
FT_Status = FT_SetBaudRate(FT_Handle, 9600)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Set parameters
FT_Status = FT_SetDataCharacteristics(FT_Handle,
FT_DATA_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Set Flow Control
FT_Status = FT_SetFlowControl(FT_Handle, FT_FLOW_NONE, 0, 0)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Display in a message box all the items that are checked.
Dim indexChecked As Integer
Dim iRelays As Integer = 0
' First show the index and check state of all selected items.
For Each indexChecked In SetBits.CheckedIndices
iRelays = iRelays + 2 ^ Val(indexChecked.ToString())
Next
' Write string data to device
Dim sOutput As String
'If iRelays < 16 Then
'sOutput = "r0" + Hex(iRelays) + Chr(13)
'Else
'sOutput = "r" + Hex(iRelays) + Chr(13)
'End If
'sOutput = Me.TextBox1.Text + Chr(13)
sOutput = "r" + Trim(Str(iRelays)) + Chr(13)
FT_Status = FT_Write_String(FT_Handle, sOutput, Len(sOutput),
BytesWritten)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Wait
Sleep(100)
' Get number of bytes waiting to be read
FT_Status = FT_GetQueueStatus(FT_Handle, FT_RxQ_Bytes)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Read number of bytes waiting
' Allocate string to recieve data
TempStringData = Space(FT_RxQ_Bytes + 1)
FT_Status = FT_Read_String(FT_Handle, TempStringData,
FT_RxQ_Bytes, BytesRead)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Close device
FT_Status = FT_Close(FT_Handle)
If FT_Status <> FT_OK Then
Exit Sub
End If
End Sub
Private Sub AudonUSB_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
Dim DeviceCount As Integer
Dim DeviceIndex As Integer
Dim TempDevString As String
' Get the number of device attached
FT_Status = FT_GetNumberOfDevices(DeviceCount, vbNullChar,
FT_LIST_NUMBER_ONLY)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Exit if no device connected
If DeviceCount = 0 Then
MsgBox("No Device Connected", MsgBoxStyle.Critical)
Exit Sub
End If
' Clear device list
DeviceList.Items.Clear()
' List devices in dropdown
For DeviceIndex = 0 To DeviceCount - 1
' Get serial number of device with index 0
' Allocate space for string variable
TempDevString = Space(16)
FT_Status = FT_GetDeviceString(DeviceIndex,
TempDevString, FT_LIST_BY_INDEX Or FT_OPEN_BY_SERIAL_NUMBER)
If FT_Status <> FT_OK Then
Exit Sub
End If
FT_Serial_Number =
Microsoft.VisualBasic.Left(TempDevString, InStr(1, TempDevString,
vbNullChar) - 1)
' Get description of device with index 0
' Allocate space for string variable
TempDevString = Space(64)
FT_Status = FT_GetDeviceString(DeviceIndex,
TempDevString, FT_LIST_BY_INDEX Or FT_OPEN_BY_DESCRIPTION)
If FT_Status <> FT_OK Then
Exit Sub
End If
FT_Description =
Microsoft.VisualBasic.Left(TempDevString, InStr(1, TempDevString,
vbNullChar) - 1)
' Add to dropdown
DeviceList.Items.Add(FT_Description + " " +
FT_Serial_Number)
Next
' Set first device
DeviceList.SelectedIndex = 0
End Sub
Private Sub DeviceList_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DeviceList.SelectedIndexChanged
Dim sDevice As String
Dim iSpace As Integer
sDevice =
DeviceList.Items.Item(DeviceList.SelectedIndex).ToString
iSpace = InStrRev(sDevice, " ")
If iSpace > 0 Then
FT_Description = Trim(Microsoft.VisualBasic.Left(sDevice,
iSpace - 1))
FT_Serial_Number =
Trim(Microsoft.VisualBasic.Mid(sDevice, iSpace + 1))
End If
End Sub
Private Sub ReadUSB_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles ReadUSB.Click
Dim BytesWritten As Integer
Dim TempStringData As String
Dim BytesRead As Integer
'Open device by serial number
FT_Status = FT_OpenBySerialNumber(FT_Serial_Number, 1,
FT_Handle)
If FT_Status <> FT_OK Then
MsgBox("Failed to open device.", , )
Exit Sub
End If
' Reset device
FT_Status = FT_ResetDevice(FT_Handle)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Purge buffers
FT_Status = FT_Purge(FT_Handle, FT_PURGE_RX Or FT_PURGE_TX)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Set Baud Rate
FT_Status = FT_SetBaudRate(FT_Handle, 9600)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Set parameters
FT_Status = FT_SetDataCharacteristics(FT_Handle,
FT_DATA_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Set Flow Control
FT_Status = FT_SetFlowControl(FT_Handle, FT_FLOW_NONE, 0, 0)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Write string data to device
Dim sOutput As String
If ReadInputs.Checked = True Then
' Read inputs
sOutput = "i0" + Chr(13)
Else
' Relay Status
sOutput = "s0" + Chr(13)
End If
FT_Status = FT_Write_String(FT_Handle, sOutput, Len(sOutput),
BytesWritten)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Wait
Sleep(100)
' Get number of bytes waiting to be read
FT_Status = FT_GetQueueStatus(FT_Handle, FT_RxQ_Bytes)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Read number of bytes waiting
' Allocate string to recieve data
TempStringData = Space(FT_RxQ_Bytes + 1)
FT_Status = FT_Read_String(FT_Handle, TempStringData,
FT_RxQ_Bytes, BytesRead)
If FT_Status <> FT_OK Then
Exit Sub
End If
' Change LED color depending on input
Dim iInput As Integer
TempStringData = Replace(TempStringData, "i0", " ")
TempStringData = Replace(TempStringData, "s0", " ")
TempStringData = Replace(TempStringData, Chr(13), " ")
TempStringData = Trim(Replace(TempStringData, Chr(10), " "))
iInput = Val(TempStringData)
If (iInput And 1) Then
LED0.BackColor = Color.LightGreen
Else
LED0.BackColor = Color.DarkGreen
End If
If (iInput And 2) Then
LED1.BackColor = Color.LightGreen
Else
LED1.BackColor = Color.DarkGreen
End If
If (iInput And 4) Then
LED2.BackColor = Color.LightGreen
Else
LED2.BackColor = Color.DarkGreen
End If
If (iInput And 8) Then
LED3.BackColor = Color.LightGreen
Else
LED3.BackColor = Color.DarkGreen
End If
If (iInput And 16) Then
LED4.BackColor = Color.LightGreen
Else
LED4.BackColor = Color.DarkGreen
End If
If (iInput And 32) Then
LED5.BackColor = Color.LightGreen
Else
LED5.BackColor = Color.DarkGreen
End If
If (iInput And 64) Then
LED6.BackColor = Color.LightGreen
Else
LED6.BackColor = Color.DarkGreen
End If
If (iInput And 128) Then
LED7.BackColor = Color.LightGreen
Else
LED7.BackColor = Color.DarkGreen
End If
' Close device
FT_Status = FT_Close(FT_Handle)
If FT_Status <> FT_OK Then
Exit Sub
End If
End Sub
End Class




 

Re: COM Lighting Control.
Post by thefamouscash on Aug 27th, 2010, 4:50pm

Please advise to which email address you sent the two emails containing VB2BBC link?
I cannot trace receipt in any of my emails.

Bob.
Re: COM Lighting Control.
Post by admin on Aug 27th, 2010, 5:55pm

on Aug 27th, 2010, 4:50pm, thefamouscash wrote:
Please advise to which email address you sent the two emails containing VB2BBC link?

I sent both emails to thefamouscash@blueyonder.co.uk and have received no 'bounce' messages. Therefore I have no reason to think they weren't delivered successfully.

Richard.

Re: COM Lighting Control.
Post by thefamouscash on Aug 28th, 2010, 11:39am

I think there must be something untoward going on.
I sent a second email directly to you and did not get a response either.
Perhaps try bobburt@blueyonder.co.uk requesting read receipt?
Still trying to find alternative code.
Bob.
Re: COM Lighting Control.
Post by admin on Aug 28th, 2010, 12:59pm

on Aug 28th, 2010, 11:39am, thefamouscash wrote:
Perhaps try bobburt@blueyonder.co.uk requesting read receipt?

I really can't see much point, because I don't think VB2BBC is going to be much help:

  1. Your code causes it to crash, and you won't have the experience to know what to do about that.
  2. I have already translated the code you listed to BBC BASIC (using VB2BBC) so I could simply let you have the translation!
  3. The code is so complex and specific to the demo environment (it seems to assume a UI with a listbox and checkboxes etc.) that I'm really not sure it will be all that useful anyway.
If you want the BBC BASIC translation just let me know and I'll list it here.

Richard.
Re: COM Lighting Control.
Post by thefamouscash on Aug 28th, 2010, 1:11pm

Thank you very much. I would appreciate that translation.
My intention to use the VB2BBC was to input small pieces of the code for translation in the hope of determining which were relevant.

This is so frustrating. ALL I want to do is sent simple ASCII codes through a USB to the device which controls relays.

I thought it was my lack of programming skills which prevented me from following your instructions through "HELP" but a friend of mine, with some considerable programming knowledge, spent two full days with me and we still could not overcome the problem.

The SYS commands seem the way but nothing seems to work.

I appreciate all your efforts and patience.

All I know is, I WILL get this problem solved, no matter how long it takes!

Bob.


Re: COM Lighting Control.
Post by admin on Aug 28th, 2010, 1:58pm

on Aug 28th, 2010, 1:11pm, thefamouscash wrote:
Thank you very much. I would appreciate that translation

OK, (partial) translation follows below:

Code:
      REM Program partially translated from Visual BASIC to BBC BASIC
      REM using VB2BBC utility ver 0.07 on Fri.27 Aug 2010,10:25:35
      
      INSTALL @lib$+"STRINGLIB"
      
      DEF PROCSetUSB_Click(FT_Serial_Number%)
      LOCAL FT_Status%, FT_Handle%, indexCheck%, iRelays%
      LOCAL FT_RxQ_Bytes%, BytesRead%, BytesWritten%
      REM Open device by serial number
      SYS `FT_OpenBySerialNumber`, FT_Serial_Number%, 1, ^FT_Handle% TO FT_Status%
      IF FT_Status% <> FT_OK THEN
        SYS "MessageBox", @hwnd%, ("Failed to open device."), 0, 0
        ENDPROC
      ENDIF
      REM  Reset device
      SYS `FT_ResetDevice`, FT_Handle% TO FT_Status%
      IF FT_Status% <> FT_OK THEN ENDPROC
      REM  Purge buffers
      SYS `FT_Purge`, FT_Handle%, FT_PURGE_RX OR FT_PURGE_TX TO FT_Status%
      IF FT_Status% <> FT_OK THEN ENDPROC
      REM  Set Baud Rate
      SYS `FT_SetBaudRate`, FT_Handle%, 9600 TO FT_Status%
      IF FT_Status% <> FT_OK THEN ENDPROC
      REM  Set parameters
      SYS `FT_SetDataCharacteristics`, FT_Handle%, FT_DATA_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE TO FT_Status%
      IF FT_Status% <> FT_OK THEN ENDPROC
      REM  Set Flow Control
      SYS `FT_SetFlowControl`, FT_Handle%, FT_FLOW_NONE, 0, 0 TO FT_Status%
      IF FT_Status% <> FT_OK THEN ENDPROC
      REM  Display in a message box all the items that are checked.
      REM  First show the index and check state of all selected items.
      FOR indexCheck% = MIN_INDEX TO MAX_INDEX
        iRelays% = iRelays% + 2 ^ VAL(FN_isboxchecked(indexCheck%))
      NEXT
      REM  Write string data to device
      sOutput$ = "r" + FN_trim(STR$(iRelays%)) + CHR$(13)
      SYS `FT_Write_String`, FT_Handle%, sOutput$, LEN(sOutput$), ^BytesWritten% TO FT_Status%
      IF FT_Status% <> FT_OK THEN ENDPROC
      REM  Wait
      SYS "Sleep", 100
      REM  Get number of bytes waiting to be read
      SYS `FT_GetQueueStatus`, FT_Handle%, ^FT_RxQ_Bytes% TO FT_Status%
      IF FT_Status% <> FT_OK THEN ENDPROC
      REM  Read number of bytes waiting
      REM  Allocate string to receive data
      TempStringData$ = STRING$(FT_RxQ_Bytes% + 1, " ")
      SYS `FT_Read_String`, FT_Handle%, !^TempStringData$, FT_RxQ_Bytes%, ^BytesRead% TO FT_Status%
      IF FT_Status% <> FT_OK THEN ENDPROC
      REM  Close device
      SYS `FT_Close`, FT_Handle% TO FT_Status%
      IF FT_Status% <> FT_OK THEN ENDPROC
      ENDPROC
      
      DEF PROCAudonUSB_Load
      LOCAL DeviceIndex%, FT_Serial_Number%, TempDevString$, FT_Status%
      LOCAL DeviceCount%, FT_Description%
      REM  Get the number of device attached
      SYS `FT_GetNumberOfDevices`, ^DeviceCount%, "", FT_LIST_NUMBER_ONLY TO FT_Status%
      IF FT_Status% <> FT_OK THEN ENDPROC
      REM  Exit if no device connected
      IF DeviceCount% = 0 THEN
        SYS "MessageBox", @hwnd%, "No Device Connected", 0, 0
        ENDPROC
      ENDIF
      REM  Clear device list
      DeviceList.Items.Clear()
      REM  List devices in dropdown
      FOR DeviceIndex% = 0 TO DeviceCount% - 1
        REM  Get serial number of device with index 0
        REM  Allocate space for string variable
        TempDevString$ = STRING$(16, " ")
        SYS `FT_GetDeviceString`, DeviceIndex%, !^TempDevString$, FT_LIST_BY_INDEX OR FT_OPEN_BY_SERIAL_NUMBER TO FT_Status%
        IF FT_Status% <> FT_OK THEN ENDPROC
        FT_Serial_Number$ = LEFT$(TempDevString$, INSTR(TempDevString$, CHR$(0)) - 1)
        REM  Get description of device with index 0
        REM  Allocate space for string variable
        TempDevString$ = STRING$(64, " ")
        SYS `FT_GetDeviceString`, DeviceIndex%, !^TempDevString$, FT_LIST_BY_INDEX OR FT_OPEN_BY_DESCRIPTION TO FT_Status%
        IF FT_Status% <> FT_OK THEN ENDPROC
        FT_Description$ = LEFT$(TempDevString$, INSTR(TempDevString$, CHR$0) - 1)
        REM  Add to dropdown
        PROCaddtolistbox(FT_Description$ + " " + FT_Serial_Number$)
      NEXT
      REM  Set first device
      DeviceList.SelectedIndex% = 0
      ENDPROC
      
      DEF PROCReadUSB_Click(FT_Serial_Number%)
      LOCAL sOutput$, TempStringData$, iInput%, FT_Status%, FT_Handle%
      LOCAL BytesWritten%, BytesRead%, FT_RxQ_Bytes%
      REM  Open device by serial number
      SYS `FT_OpenBySerialNumber`, FT_Serial_Number%, 1, ^FT_Handle% TO FT_Status%
      IF FT_Status% <> FT_OK THEN
        SYS "MessageBox", @hwnd%, "Failed to open device", 0, 0
        ENDPROC
      ENDIF
      REM  Reset device
      SYS `FT_ResetDevice`, FT_Handle% TO FT_Status%
      IF FT_Status% <> FT_OK THEN ENDPROC
      REM  Purge buffers
      SYS `FT_Purge`, FT_Handle%, FT_PURGE_RX OR FT_PURGE_TX TO FT_Status%
      IF FT_Status% <> FT_OK THEN ENDPROC
      REM  Set Baud Rate
      SYS `FT_SetBaudRate`, FT_Handle%, 9600 TO FT_Status%
      IF FT_Status% <> FT_OK THEN ENDPROC
      REM  Set parameters
      SYS `FT_SetDataCharacteristics`, FT_Handle%, FT_DATA_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE TO FT_Status%
      IF FT_Status% <> FT_OK THEN ENDPROC
      REM  Set Flow Control
      SYS `FT_SetFlowControl`, FT_Handle%, FT_FLOW_NONE, 0, 0 TO FT_Status%
      IF FT_Status% <> FT_OK THEN ENDPROC
      REM  Write string data to device
      IF ReadInputs.Checked = TRUE THEN
        REM  Read inputs
        sOutput$ = "i0" + CHR$(13)
      ELSE
        REM  Relay Status
        sOutput$ = "s0" + CHR$(13)
      ENDIF
      SYS `FT_Write_String`, FT_Handle%, sOutput$, LEN(sOutput$), ^BytesWritten% TO FT_Status%
      IF FT_Status% <> FT_OK THEN ENDPROC
      REM  Wait
      SYS "Sleep", 100
      REM  Get number of bytes waiting to be read
      SYS `FT_GetQueueStatus`, FT_Handle%, ^FT_RxQ_Bytes% TO FT_Status%
      IF FT_Status% <> FT_OK THEN ENDPROC
      REM  Read number of bytes waiting
      REM  Allocate string to recieve data
      TempStringData$ = STRING$(FT_RxQ_Bytes% + 1, " ")
      SYS `FT_Read_String`, FT_Handle%, !^TempStringData$, FT_RxQ_Bytes%, ^BytesRead% TO FT_Status%
      IF FT_Status% <> FT_OK THEN ENDPROC
      REM  Change LED color depending on input
      TempStringData$ = FN_findreplace(TempStringData$, "i0", " ", 0)
      TempStringData$ = FN_findreplace(TempStringData$, "s0", " ", 0)
      TempStringData$ = FN_findreplace(TempStringData$, CHR$(13), " ", 0)
      TempStringData$ = FN_trim(FN_findreplace(TempStringData$, CHR$(10), " ", 0))
      iInput% = VAL(TempStringData$)
      IF (iInput% AND 1) THEN
        LED0.BackColor = Color.LightGreen
      ELSE
        LED0.BackColor = Color.DarkGreen
      ENDIF
      IF (iInput% AND 2) THEN
        LED1.BackColor = Color.LightGreen
      ELSE
        LED1.BackColor = Color.DarkGreen
      ENDIF
      IF (iInput% AND 4) THEN
        LED2.BackColor = Color.LightGreen
      ELSE
        LED2.BackColor = Color.DarkGreen
      ENDIF
      IF (iInput% AND 8) THEN
        LED3.BackColor = Color.LightGreen
      ELSE
        LED3.BackColor = Color.DarkGreen
      ENDIF
      IF (iInput% AND 16) THEN
        LED4.BackColor = Color.LightGreen
      ELSE
        LED4.BackColor = Color.DarkGreen
      ENDIF
      IF (iInput% AND 32) THEN
        LED5.BackColor = Color.LightGreen
      ELSE
        LED5.BackColor = Color.DarkGreen
      ENDIF
      IF (iInput% AND 64) THEN
        LED6.BackColor = Color.LightGreen
      ELSE
        LED6.BackColor = Color.DarkGreen
      ENDIF
      IF (iInput% AND 128) THEN
        LED7.BackColor = Color.LightGreen
      ELSE
        LED7.BackColor = Color.DarkGreen
      ENDIF
      REM  Close device
      SYS `FT_Close`, FT_Handle% TO FT_Status%
      IF FT_Status% <> FT_OK THEN ENDPROC
      ENDPROC 

Please note:
I can see how this code can be modified quite easily to do exactly what you want; can you? It's an easy task for an experienced BBC BASIC programmer, but quite daunting for a beginner.

It's frustrating that I don't have the actual device here, because I could almost certainly get everything working in a few minutes. I wish you luck in your endeavours!

Richard.
Re: COM Lighting Control.
Post by thefamouscash on Aug 28th, 2010, 2:10pm

Thank you so much!
Starting immediately.
Will let you know if I manage.
Regards,
Bob.
Re: COM Lighting Control.
Post by thefamouscash on Aug 29th, 2010, 6:01pm

I have really tried hard to make this work with ZERO success. I have read as much as I can; I have posted on the Web for other help to stop pestering you; I have contacted FDTI; I have asked anyone who knows anything about computing. . . ZERO success.
The problem is the variables. What the devil is FT_Handle? How are all of them found.
I HAVE attemptd to run the code using what I hoped to be sensible choices. Even when I have run with set variables, I get the message, "No such variable" message, although EVERY variable HAS been assigned (and prints out)
EG.

SYS `FT_GetNumberOfDevices`, ^DeviceCount%, "", FT_LIST_NUMBER_ONLY TO FT_Status%

produces the message but everything is set.

I have worked 15 hours straight on this and need some sleep. Perhaps suicide is an option.
Bob.
Re: COM Lighting Control.
Post by admin on Aug 29th, 2010, 9:26pm

on Aug 29th, 2010, 6:01pm, thefamouscash wrote:
Code:
SYS `FT_GetNumberOfDevices`, ^DeviceCount%, "", FT_LIST_NUMBER_ONLY TO FT_Status% 
produces the message but everything is set.

Clearly everything is not set! It really ought to be easy to discover which of the variables is causing the 'No such variable' error, either by printing each one out, or using the List Variables utility. One or other of these variables must definitely not be defined if you are receiving that error:

`FT_GetNumberOfDevices`
FT_LIST_NUMBER_ONLY

When the error occurs, open the List Variables window and scroll down looking for those two variables. I bet one of them isn't there!

Whilst of course I sympathise with your plight, if you're really at the stage of not being able to discover the cause of a 'No such variable' error I would suggest that you're too inexperienced at programming in BBC BASIC to tackle the task you have set yourself.

My previous offer remains. If you're prepared to lend me the device you are trying to control I will write the code to drive it.

Richard.
Re: COM Lighting Control.
Post by admin on Aug 31st, 2010, 10:24pm

on Aug 29th, 2010, 9:26pm, Richard Russell wrote:
One or other of these variables must definitely not be defined if you are receiving that error:

`FT_GetNumberOfDevices`
FT_LIST_NUMBER_ONLY

Surprisingly, it turns out that the OP's difficulty stemmed from not distinguishing between the apostrophe character ' (which some people call single quote) and the grave accent character ` (which some people call a backtick or backquote):

http://en.wikipedia.org/wiki/Grave_accent

In BBC BASIC the apostrophe (CHR$39) is used in the INPUT and PRINT statements to signify that output should move onto the next line. The grave accent (CHR$96) is a valid character within (and at the beginning of) a variable name. Thus in BBC BASIC this is valid code:

Code:
  `variable` = 12345
  PRINT ' `variable` 

Richard.

Re: COM Lighting Control.
Post by thefamouscash on Sep 1st, 2010, 12:03am

Thank you for the information.
I stand corrected. I should have taken the time to attend to your clear instruction about CHR$ 96 instead of assuming it was the single quiote. I confess I was unaware of the usage of that character as part of the variable.
Still working on the program but, at least, now have a chance to make it work.
Regards,
Bob.
Re: COM Lighting Control.
Post by John Fisher on Sep 7th, 2010, 09:34am

Have you managed to get this working? I'd have thought that you could use the serial examples in the BB4W manual more easily than the dll method. Did you install the Audon driver? Does a new COM port then appear in your Control Panel -> System -> Hardware -> Device manager? Can you communicate with Hyperterminal and send/receive command/response strings with 9600/8n1 protocol?
Re: COM Lighting Control.
Post by thefamouscash on Sep 7th, 2010, 5:08pm

When unit was purchased, drivers downloaded automatically. Unit "clicks" when Audon's software form (like hyperterminal?) is used and box lights according to which of the eight relays are on. Ititally, in addition to COMS 1 and 2, a COM3 appeared. Since I have been endlessly experimenting, this now shows as COM 5. (No idea why). I believe Vista did away with Hyperterminal.