ScriptBasic
May 22, 2012, 02:43:39 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: The ScriptBasic User, Developer and extension module guides are available at the WIKI.
 
   Home   Wiki Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Print to ttyS0  (Read 340 times)
KenHorse
Newbie
*
Posts: 10


« on: January 22, 2012, 05:08:10 PM »

Obviously this in Linux

I have an external hardware device that requires the following sent to it via RS232:

1*21999<CR>

So in Scriba, my line is (after opening Open /dev/ttyS0 For Output as #2)

Print #2, "1*21999\n"

But it doesn't seem to send Chr(13) correctly (Chr(13) is CR, right?)

If I send 1*21999 via minicom, it works properly but if sent from Scriba, the external device ignores it.
Logged
support
Administrator
*****
Posts: 409


« Reply #1 on: January 22, 2012, 06:33:50 PM »

Try "1*21999\r\n"

\r = RETURN
\n = LINEFEED
Logged
KenHorse
Newbie
*
Posts: 10


« Reply #2 on: January 22, 2012, 06:57:09 PM »

Nope, didn't fix it.
Logged
support
Administrator
*****
Posts: 409


« Reply #3 on: January 22, 2012, 07:14:42 PM »

ScriptBasic assumes that the tty port is setup correctly at the Linux level.

When you say it isn't working, are you seeing anything or just not doing line termination correctly?

If your device is only looking for a CHR(13) (RETURN) for a line terminator then just use \r only.
Logged
KenHorse
Newbie
*
Posts: 10


« Reply #4 on: January 22, 2012, 07:22:39 PM »

I probably need to look at the data stream because I can echo from the bash prompt (echo 1*21999 > /dev/ttyS0 and that works fine. Between that and minicom, it shows the port is configured ok under Linux itself. I have looked at the output on another computer running a term prog and it *looks* ok but obviously it isn't.

It's just from within Scriba that it doesn't work.
Logged
support
Administrator
*****
Posts: 409


« Reply #5 on: January 22, 2012, 07:25:58 PM »

Please post the relevant code you are using to communicate with the serial port.

I haven't tried using SB with a serial port before but I see no reason it shouldn't work.

This works even though it isn't a tty serial port in the true sense.

Code:
OPEN "/dev/tty" FOR OUTPUT AS 1

PRINT #1,"Test\n"
LINE INPUT #1, i
PRINT i

jrs@laptop:~/sb/test$ scriba ttytest.sb
Test
jrs@laptop:~/sb/test$

« Last Edit: January 22, 2012, 07:40:27 PM by support » Logged
RONB
Newbie
*
Posts: 35


« Reply #6 on: January 22, 2012, 11:41:26 PM »

The line feed is different between windows and Linux.
print
linux
\n is chr(10)
\r is chr(13)
chr(13) is chr(13)
chr(10) is chr(10)
windows
\n is chr(13)chr(10)
\r is chr(13)
chr(13) is chr(13)
chr(10) is chr(13)chr(10)

An easy way to check is to send the output to a file and then check the file with a zipzap, hex editor.

Logged
KenHorse
Newbie
*
Posts: 10


« Reply #7 on: January 24, 2012, 05:25:07 PM »

Thanks for the info guys. I was able to make it work -it turns out it was a problem caused by changing baud rates which caused ttyS0 to send extraneous characters ( I was changing baud from 57600 to 9600, sent my string and then reset the baud to 57600.

Now I have another problem but I'll start a new thread about that as it is installation related on a different Linux computer
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!