0

OK. I'm trying to store camera parameters for a cameralink camera in a Python config file, and then pass those parameters on to the camera via a serial port. Does any one know how to do this? This is what I have so far:

Config File

[BAUDRATE]
BAUDRATE = 9600

[ROI]
Width = 16
Height = 16
OffsetX = 3
OffsetY = 3

My code

import configparser
import serial

List_of_Camera_Commands = []

# Establish serial port
'''
ser = serial.Serial('/dev/ttyUSB0')
print(ser.name)
ser.baudrate = 192000
ser.write(stuff to write)
ser.read()
'''

CameraConfig = configparser.ConfigParser()
CameraConfig.read("CameraConfig.conf")

#---------Code to read in Config file Options and cast as ints----

for name in CameraConfig.sections():
     for option in CameraConfig.options(name):
         Number_Value = CameraConfig.getint(name, option)
         print(name, ": ", Number_Value)
         Temp_command = [name,  Number_Value]
         List_of_Camera_Commands.append(Temp_command)

print(List_of_Camera_Commands)

#ser.write(List_of_Camera_Commands)       ------> write to serial?
martineau
  • 119,623
  • 25
  • 170
  • 301
Marco Peterson
  • 81
  • 1
  • 1
  • 4
  • What library are you using to access the serial port (`serial` is not a standard Python module)? – martineau Jul 11 '17 at 17:37
  • @martineau yes, it is, `serial` is third party python module [pyserial](https://pypi.python.org/pypi/pyserial) – vlk Jul 12 '17 at 14:39
  • OK. In that case you need to get the values from the config file (using `Configparser`) and then use it when you [_create_](http://pyserial.readthedocs.io/en/latest/shortintro.html) the serial port with `serial.Serial`, not `write` the data to/through the port afterwards). Suggest you try doing that and if you still have problems, then ask another questions with the details. – martineau Jul 12 '17 at 14:50
  • P.S. Or, configure the port after creating it with the config data as shown in the examples in the [documentation](http://pyserial.readthedocs.io/en/latest/shortintro.html#configuring-ports-later). – martineau Jul 12 '17 at 15:00

0 Answers0