Author |
Topic: problem with the syntax for serial communication (Read 642 times) |
|
FBack
New Member
member is offline
Posts: 10
|
|
problem with the syntax for serial communication
« Thread started on: Jan 7th, 2014, 2:13pm » |
|
Hi
I am writing a program that reads and displays data from the battery charger (only one-way communication).
I ran into a problem. When the data stream from the charger stops when charging or discharging is finished, the program freezes until I pressed the corresponding key on the charger. As a consequence, can not I add notifications to press this button on the charger to continue and options for automatic storage of collected data in automatic cycle charge/discharge mode.
In the Just Basic is the solution as follows (from JB help):
It is Recommended That You Set Certain handshaking switches are That your program does not just freeze When waiting for data to come in or trying to send data. It do this, we add DS0, CS0, and rs switches as Below. Needs You May Differ, But These work well for most applications. Notice we use a Different communications speed in this example. open "com2: 19200, n, 8,1, DS0, CS0, rs" for random as # commHandle
Unfortunately, I can not find the way how to implement it in LBB.
I really appreciate any help you can provide.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: problem with the syntax for serial communicati
« Reply #1 on: Jan 7th, 2014, 4:55pm » |
|
on Jan 7th, 2014, 2:13pm, FBack wrote:When the data stream from the charger stops when charging or discharging is finished, the program freezes. |
|
You should only read the amount of data available, for example (taken from the LB docs):
Code:dataRead$ = input$(#commHandle, lof(#commHandle)) If you use that technique it should be impossible for the program to 'freeze'. Perhaps you can list the code you are using to read from the serial port.
If that doesn't solve the problem you can simulate the effect of LB's timeout settings by calling the SetCommTimeouts API:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa363437.aspx
If you want help with that ask here again.
Richard.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: problem with the syntax for serial communicati
« Reply #2 on: Jan 8th, 2014, 09:05am » |
|
Here is how to set the timeout to zero in LBB:
Code: open "com1:19200,n,8,1" for random as #comm
hcomm = hwnd(#comm)
struct CTO, RIT as long, RTTM as long, RTTC as long, _
WTTM as long, WTTC as long
CTO.RIT.struct = -1
calldll #kernel32, "SetCommTimeouts", hcomm as ulong, _
CTO as struct, r as long But, as I said before, if you only read the number of bytes currently available it should not be necessary to use this technique to avoid the program 'freezing'.
Richard.
|
|
Logged
|
|
|
|
FBack
New Member
member is offline
Posts: 10
|
|
Re: problem with the syntax for serial communicati
« Reply #3 on: Jan 8th, 2014, 09:32am » |
|
Thanks Richard for useful idea. Yes, by using the LOF is the problem solved.
The basic problem was that I misunderstood the description of the charger data protocol.
Charger Imax B6 (Clone) using the following protocol:
http://simbox.nl/index.htm?p=IMAX%20Protocol&refr=1800
Quote:In fact the string should always be 76 bytes long, drop it when it's not! |
|
Here was my fault, I thought that all data packets strictly 76 characters long (not necessary, it can be divided into 2 parts). Consequently, by using the LOF I lost 2/3 of the data. Why this happens is, I was not paying attention and I'm hoping that the simple idea from JB is appropriate.
Thanks again for your help and for your development of LBB.
|
|
Logged
|
|
|
|
|