Sent Bytes to COM Port

Discussions about the Liberty BASIC language, with particular reference to LB Booster
steinche
Posts: 2
Joined: Wed Jul 08, 2020 7:16 am

Sent Bytes to COM Port

Post 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
guest
Site Admin
Posts: 192
Joined: Tue Apr 03, 2018 1:34 pm

Re: Sent Bytes to COM Port

Post 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.
Steini63
Posts: 3
Joined: Fri Nov 02, 2018 11:49 pm

Re: Sent Bytes to COM Port

Post 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
Steini63
Posts: 3
Joined: Fri Nov 02, 2018 11:49 pm

Re: Sent Bytes to COM Port

Post by Steini63 »

Too late :?
steinche
Posts: 2
Joined: Wed Jul 08, 2020 7:16 am

Re: Sent Bytes to COM Port

Post by steinche »

Hello guest an Steini63,

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

Kind regards,
Eric