Page 1 of 1

Sent Bytes to COM Port

Posted: Wed Jul 08, 2020 7:35 am
by steinche
Hello LBB user,
I'm new and I have what may be a fairly simple problem.
I want to send four bytes A0 01 02 A3 (hex) to the COM port.

The syntax:

Code: Select all

Print #ComPort, CHR$(A0)+CHR$(01)+CHR$(02)+CHR$(A3);
or

Code: Select all

Print #ComPort, DECHEX$(160)+DECHEX$(01)+DECHEX$(02)+DECHEX$(163);
does not work.

Does anyone have a tip for me?

Thanks,
Eric

Re: Sent Bytes to COM Port

Posted: Wed Jul 08, 2020 4:04 pm
by guest
steinche wrote:
Wed Jul 08, 2020 7:35 am
Does anyone have a tip for me?
It should be:

Code: Select all

Print #ComPort, CHR$(&HA0)+CHR$(&H01)+CHR$(&H02)+CHR$(&HA3);
or

Code: Select all

Print #ComPort, CHR$(160)+CHR$(1)+CHR$(2)+CHR$(163);

The &H prefix won't make any difference in the case of 01 and 02, but is essential for the A0 and A3.

Re: Sent Bytes to COM Port

Posted: Wed Jul 08, 2020 4:09 pm
by Steini63
Hi Eric!

You have to use the prefix for HEX-numbers "&h". This should work:

Code: Select all

NoMainWin            'don't show console window

'ATTENTION: The code for open a serial port is different from Liberty-Basic:
Open "COM3: baud=9600 parity=n data=8 stop=1 odsr=off octs=off idsr=off" For Output As #ComPort

Print #ComPort, CHR$(&hA0)+CHR$(&h01)+CHR$(&h02)+CHR$(&hA3);

Close #ComPort
Regards
Frank

Re: Sent Bytes to COM Port

Posted: Wed Jul 08, 2020 4:11 pm
by Steini63
Too late :?

Re: Sent Bytes to COM Port

Posted: Wed Jul 15, 2020 8:50 am
by steinche
Hello guest an Steini63,

please excuse my late reply!
Thank you for the decisive tip. Works flawlessly :D

Kind regards,
Eric