Author |
Topic: COM Lighting Control. (Read 602 times) |
|
thefamouscash
New Member
member is offline


Posts: 17
|
 |
Re: COM Lighting Control.
« Reply #20 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.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: COM Lighting Control.
« Reply #21 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:
Your code causes it to crash, and you won't have the experience to know what to do about that. I have already translated the code you listed to BBC BASIC (using VB2BBC) so I could simply let you have the translation! 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.
|
|
Logged
|
|
|
|
thefamouscash
New Member
member is offline


Posts: 17
|
 |
Re: COM Lighting Control.
« Reply #22 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.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: COM Lighting Control.
« Reply #23 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:
Constants are not declared (because I don't know what their values are!). SYS routine names use the CHR$96 (`) convention because that's what I prefer in my own code. I've not bothered to translate code you won't need (e.g. the UI code which isn't relevant). 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.
|
|
Logged
|
|
|
|
thefamouscash
New Member
member is offline


Posts: 17
|
 |
Re: COM Lighting Control.
« Reply #24 on: Aug 28th, 2010, 2:10pm » |
|
Thank you so much! Starting immediately. Will let you know if I manage. Regards, Bob.
|
|
Logged
|
|
|
|
thefamouscash
New Member
member is offline


Posts: 17
|
 |
Re: COM Lighting Control.
« Reply #25 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.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: COM Lighting Control.
« Reply #26 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.
|
| « Last Edit: Aug 29th, 2010, 9:33pm by admin » |
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: COM Lighting Control.
« Reply #27 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.
|
|
Logged
|
|
|
|
thefamouscash
New Member
member is offline


Posts: 17
|
 |
Re: COM Lighting Control.
« Reply #28 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.
|
|
Logged
|
|
|
|
John Fisher
Guest
|
 |
Re: COM Lighting Control.
« Reply #29 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?
|
|
Logged
|
|
|
|
thefamouscash
New Member
member is offline


Posts: 17
|
 |
Re: COM Lighting Control.
« Reply #30 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.
|
|
Logged
|
|
|
|
|