#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    Newbie. Serial Data & COM Ports.


    I want to monitor serial ASCI data arriving at a USB port via a RS232 to USB converter.


    A number years ago I wrote a QBasic program on a PC with a genuine serial port to perform a similar task and used a command to prepare the port setting baud rate, data bits and timeouts etc

    OPEN "com1:9600,N,8,1,cd0,cs0,ds0,op0,rs,tb512,rb512" FOR RANDOM AS #2

    and the following would identify the arrival of data at the port and start the decoding subroutine.

    ON COM(1) GOSUB READRX


    I would like to create a similar program using Python but have not yet been able to find information regarding establishing the coms with external devices. As my pc does not have a 'genuine' serial port the solution must be able to work through the USB port and the RS232 converter.

    Using Python on a Windows XP PC

    Any help much appeciated.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,931
    Rep Power
    481
    I liked the abasic play command.

    In python, you can try

    with inf as open('com1','r'):
    [indent]inf.read(4) # read 4 bytes

    I don't know how clever you'll need to be to make the code interrupt driven as your qbasic code probably was.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo