Liberty BASIC Community Forum
« rs232 without chr$(13),chr$(10) is possible? »

Welcome Guest. Please Login or Register.
Mar 26th, 2017, 1:56pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: rs232 without chr$(13),chr$(10) is possible?  (Read 290 times)
monini64
New Member
Image


member is offline

Avatar




PM


Posts: 8
xx rs232 without chr$(13),chr$(10) is possible?
« Thread started on: Feb 26th, 2017, 1:37pm »

i need send a message for rs232 port but i need this havent chr$(13) and chr$(10) is possible?
Furthermore, i need received "n" bytes but the string havent chr$(13) and chr$(10)
i need, any think like this, read rs232 port "n" byte, is possible?
thanks in advance


« Last Edit: Feb 26th, 2017, 1:38pm by monini64 » User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5216
xx Re: rs232 without chr$(13),chr$(10) is possible?
« Reply #1 on: Feb 26th, 2017, 2:25pm »

Yes, very possible. When you send the message with the print command use the ; character to suppress the CRLF character pair.

So print #port, msg$;

When reading it matters less, you will get the msg$ in the buffer with or without the CRLF pair.


http://lbpe.wikispaces.com/AccessingSerialPort
« Last Edit: Feb 26th, 2017, 2:27pm by Rod » User IP Logged

monini64
New Member
Image


member is offline

Avatar




PM


Posts: 8
xx Re: rs232 without chr$(13),chr$(10) is possible?
« Reply #2 on: Feb 26th, 2017, 5:01pm »

thanks for answer, an the other question how read ¨n¨bytes without chr$(13),chr$(10) is possble
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5216
xx Re: rs232 without chr$(13),chr$(10) is possible?
« Reply #3 on: Feb 27th, 2017, 01:48am »

If the device sends ABC as the message you will have three characters in the input buffer. It is more usual for devices to add a delimiter character.

So you need to be very specific about the message you are sent. Is it fixed width or does it have a delimiter at the end of a variable width message?

If you can be more specific about how the device formats the message we can show you code to receive and parse it.

It is all explained in the wiki tutorial that I posted the link to. To get three characters back you would do this

Code:
dataRead$ = input$(#commHandle, 3)
 


But will it always be three characters? how is "n" defined?
« Last Edit: Feb 27th, 2017, 03:56am by Rod » User IP Logged

monini64
New Member
Image


member is offline

Avatar




PM


Posts: 8
xx Re: rs232 without chr$(13),chr$(10) is possible?
« Reply #4 on: Mar 17th, 2017, 05:52am »

how i can use rs232 API calls (calldll #kernel32) for transmit and receive data, works api without compiler?

« Last Edit: Mar 17th, 2017, 06:17am by monini64 » User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5216
xx Re: rs232 without chr$(13),chr$(10) is possible?
« Reply #5 on: Mar 17th, 2017, 06:04am »

You don't need api, Liberty is perfectly capable of sending and receiving ANY type of data whether chr$(X) is involved or not.

Tell us exactly what message you want to send and what message you expect to receive

#com "xYz";chr$(13);

Will send only xYz and a single chr$(13)

Liberty does not care what is returned if the device sends "xYz" and chr$(13) then that's exactly what you will get from the serial buffer loaded into your data read string.

Try and tell us more about why you think you need api because a don't currently understand what the problem is.
User IP Logged

monini64
New Member
Image


member is offline

Avatar




PM


Posts: 8
xx Re: rs232 without chr$(13),chr$(10) is possible?
« Reply #6 on: Mar 17th, 2017, 06:25am »

i use this code


msg$=CHR$(129)+CHR$(140)+CHR$(241)+CHR$(129)+CHR$(127
A$=CHR$(0)
open "COM2:360,n,8,1,ds0,cs0,rs" for random as #comm

print #comm, A$ 'start timer
close #comm 'end timer
' start timer to end timer must be 25 ms

' star timer 2
open "COM2:10400,n,8,1,ds0,cs0,rs" for random as #comm
' end timer2
' start timer2 to end timer2 must be 25 ms
'but withot compiler star time2 to end timer2 is 0.2 seconds
' righ now
print #comm, b$
close #comm

i need tx=12v for 25ms (transmit 0 at 360 bps) , tx= -12; only wait 25 ms is enought, and inmediatly a need send msg$ at 10400 bps, but withou compiler the time to close com an open com with bps changed is 0.2 second, i too long

a i thinks use api for doing this works, i open to see to other opcion



User IP Logged

monini64
New Member
Image


member is offline

Avatar




PM


Posts: 8
xx Re: rs232 without chr$(13),chr$(10) is possible?
« Reply #7 on: Mar 17th, 2017, 06:56am »

i need this
http://i.imgur.com/wMTIZaT.png

with digital analizer
http://i.imgur.com/2l1DuO0.png
« Last Edit: Mar 17th, 2017, 07:00am by monini64 » User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5216
xx Re: rs232 without chr$(13),chr$(10) is possible?
« Reply #8 on: Mar 17th, 2017, 07:32am »

Ok beginning to understand, think you would be far better off with an Arduino handling the serial com of the device then linking to the pc.

The serial port is going to be hard to work with like this. You will never get it to open and close that quickly even with an api call.

You might try opening once at 10400 and sending 260 null characters ahead of your message. The stop bit might interfere but it depends how sensitive the receiver is. It is still a kludge.

A few lines of code on an Arduino would easily meet your timing needs. And it is relatively easy to send the messages on to a PC at a more relaxed pace. You would get plenty of help from the Arduino community.
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5216
xx Re: rs232 without chr$(13),chr$(10) is possible?
« Reply #9 on: Mar 17th, 2017, 07:49am »

Is there a web page for the device you are trying to communicate with?
User IP Logged

monini64
New Member
Image


member is offline

Avatar




PM


Posts: 8
xx Re: rs232 without chr$(13),chr$(10) is possible?
« Reply #10 on: Mar 17th, 2017, 08:06am »

no exactly, is for car diagnostic, then protocol name is kwp2000,

http://raviprashanthsn-technical.blogspot.com.ar/2013/10/kwp2000-basic-information.html

i have intersting in kwp2000 Fast Initialization, i use a pic or y can use arduino, but i need two serial comunication, one with car and other with pc, y like use only one, pc with rs232 -12v y 12v to 0v and 12v convert, directly with car, in c++ i can do it but i more comfortable with basic
« Last Edit: Mar 17th, 2017, 08:15am by monini64 » User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5216
xx Re: rs232 without chr$(13),chr$(10) is possible?
« Reply #11 on: Mar 18th, 2017, 09:38am »

Richard has advised that you can use the EscapeCommFunction with _SETBREAK or _CLRBREAK to achieve what you need. I have not used this before. The wiki tutorial shows how to use the API function. Something like this.


Code:
print "setting break"
CALLDLL #kernel32, "EscapeCommFunction", hFileHandle as ulong, _SETBREAK as long,_
result as long

'delay here, either a while wend loop to get 25ms or
CallDLL #kernel32, "Sleep",25 As ULong,ret As Void


print "clearing break"
CALLDLL #kernel32, "EscapeCommFunction", hFileHandle as ulong, _CLRDTR as long,_
result as long 


« Last Edit: Mar 18th, 2017, 09:46am by Rod » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls