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

    Join Date
    Mar 2014
    Posts
    2
    Rep Power
    0

    Read serial port data using Digi ConnectPort and send wirelessly


    Hi all,

    I am extremely new to Python but discovered that I need it in order to programme my Digi ConnectPort TS1W MEI gateway. What I want to do is read from the serial port periodically then send this data wirelessly to the nearest access point. What I have started with is trying to open, read, write and close the serial port, and I have found the following sample code online:

    Code:
      try:
        serfd = os.open( '/com/0', os.O_RDWR | os.O_NONBLOCK)
      except:
        ( ... handle port in use or invalid name ... )
    
      try:
        data = os.read( serfd, max_bytes)
     
      except OSError, e:
        if( e.errno == errno.EAGAIN):  # EAGAIN just means NO data ready, try again
          ( ... handle NO data received or response timeout here ... )
     
        else: # other errors
          ( ... handle port faults - likely fatal ... )
          traceback.print_exc() # make sure you show the user what error was
    
      try:
        count = os.write( serfd, data)
      except:
        ( ... handle port faults - likely fatal ... )
    
       try:
        os.close( serfd)
      except:
        pass # ignore errors here
    Would anyone be able to give me any tips on how to complete the script that I would need to carry out the simple process that I've mentioned? Or if anyone could point to the place I could find some helpful sample code, as my Google searches have not yet proved to be very fruitful. Any suggestion would be welcome.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,709
    Rep Power
    480
    You'd need to insert a first line

    import os


    And for all occurrences of similar lines, change

    ( ... handle port in use or invalid name ... )

    to

    print('... handle port in use or invalid name ...')


    And then you'd probably need to make other changes as well.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2014
    Posts
    2
    Rep Power
    0

    Arrow


    Ok, so I've got something interesting:

    https://www.dropbox.com/sh/1yq4x09xi5w4dsm/CuuZCIjwRT

    But it doesn't work. Error message states:

    Code:
    Traceback (most recent call last):
    File “WEB/python/serial_loopback.py”, line 28, 
    in ? import serial.
    Import Error: No module named serial.
    when I ran the command:

    python serial_loopback.py
    Any ideas anyone?

IMN logo majestic logo threadwatch logo seochat tools logo