weqaar / libflir

Python FLIR API
MIT License
5 stars 2 forks source link

Question on sending commands via Serial #1

Open JLee21 opened 6 years ago

JLee21 commented 6 years ago

Hi!

I was wondering if you had any code that exemplified sending the Flir commands via serial?

Is it something as simple as this:


functions = FLIR_Functions()

noop_cmd = functions.noop()

ser = serial.Serial('my_port', 9600)
ser.write(noop_cmd)
weqaar commented 6 years ago

Hi,

Yes, it is as simple.

This is how I write to serial using the commands lib, a bit long explanation but I hope it helps:

from libflir import *

libFLIR = FLIR_Functions()
_serial_FLIR = Serial_Functions_FLIR()
_serial_FLIR.serial_init_FLIR()

This is the Serial_Functions_FLIR class:

class Serial_Functions_FLIR():

        def __init__(self):
                self.parse = Parser_Functions()
                self.parse.parser_init()
                self.parse.ConfigSectionMap()

        def serial_init_FLIR(self):
                _section = 'FLIR'
                _device = self.parse.getSectionOption(_section, 'device')
                _baudrate = int(self.parse.getSectionOption(_section, 'baudrate'))
                _parity = self.parse.getSectionOption(_section, 'parity')
                _stopbits = int(self.parse.getSectionOption(_section, 'stopbits'))
                _bytesize = int(self.parse.getSectionOption(_section, 'bytesize'))
                _timeout = int(self.parse.getSectionOption(_section, 'timeout'))
                _inter_byte_delay = float(self.parse.getSectionOption(_section, 'inter_byte_delay'))
                self.ser = serial.Serial (port = _device, baudrate = _baudrate, timeout = _timeout, \
                           interCharTimeout = _inter_byte_delay, parity = _parity, stopbits = _stopbits, bytesize = _bytesize)
                self.ser.flush()

        def receive(self, _bufsize):
                _buf = self.ser.read(_bufsize).encode('hex')
                self.flush_buffer()
                return _buf

        def serial_write(self, _cmd):
                self.ser.write(_cmd)
                print "wrote: " + _cmd

        def serial_read(self, _bytes):
                return self.ser.read(_bytes).encode('hex')

        def get_serial_conf(self):
                print self.ser.getSettingsDict()

        def flush_buffer(self):
                self.ser.flush()

This is what the conf file looks like, note the INTER_BYTE_DELAY required for TAU 3xx:

[FLIR]
DEVICE=/dev/ttyUSB0
BAUDRATE=57600
PARITY=N
STOPBITS=1
BYTESIZE=8
TIMEOUT=0
INTER_BYTE_DELAY=0.1

This is how the command is written to serial, as an example:

_serial_FLIR.serial_write(libFLIR.camera_reset())

We use a piece of code that is like an RPC server listening on UDP, bunch of async threads that get data in/out of the RPC<->Queues and write to serial, let me know if you need any further assistance and I will be happy to assist you there.

weqaar commented 5 years ago

Hi, if you are still looking for a solution or an improvement - here

Thanks.

weqaar commented 5 years ago

Hi,

That is some good work, if possible could you please share the code updates and maybe few tests with us?

Thanks,

Weqaar A. Janjua

On Tue, 9 Apr 2019 at 21:23, JC Lee notifications@github.com wrote:

Thanks @weqaar https://github.com/weqaar I see you added some useful files related to the Serial connection. About a year ago, what I ended up doing is extending your original code base... here's an example usage...

from flir import Tau

tau = Tau()

tau()


Core_Sensors Core_Sensor(temp_c=37.799999999999997, raw=22.149000000000001, housing_temp=38.18, core_status={'NUC Switch': 'normal', 'Gain Switch': 'normal', 'High Core Temperture': False, 'FFC': 'normal', 'FFC_2': 'normal'}, accelerometer=None) Plancks Planks(R=366545, B=1428.0, F=1.0, O=342.0) Digital_Output_Mode Digital_Output_Mode(common='disabled', xp_mode='CMOS_14bit', lvds_mode='disabled', xp_bit_depth='8bit_post_agc', lvds_bit_depth='14bit') Spot_Meter_Data Spot_Meter_Data(mode='counts', sync_flag='Valid Frame', frame_counter=19301, spot_data=3431.5, std_dev=11.5, min_val=855.0, max_val=866.25, min_coord_x=163, min_coord_y=129, max_coord_x=159, max_coord_y=134, Spot_Meter_Coords=Spot_Meter_Coords(sync_flag='Valid Frame', frame_counter=19305, left_top_x=158, left_top_y=118, right_bottom_x=177, right_bottom_y=137)) Spot_Meter_Coords Spot_Meter_Coords(sync_flag='Valid Frame', frame_counter=19305, left_top_x=158, left_top_y=118, right_bottom_x=177, right_bottom_y=137)TLIN_Status TLIN_Status(output_mode='high_resolution', status='Enabled') Scene_Params Scene_Params(emis=0.5999755859375, temp_bkg=75.0, tran_win=1.0, temp_win=0.59999999999999998, tran_atm=1.0, temp_atm=25.0, refl_win=0.0, temp_refl=25.0)****

I had also started work on writing unit tests for each every API function call, so one could test everything out without even being connected to the FLIR camera.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/weqaar/libflir/issues/1#issuecomment-481420318, or mute the thread https://github.com/notifications/unsubscribe-auth/ACo3YR-rsPxemujuvf9R-H4Rytc8LDhrks5vfPaugaJpZM4R_OJe .

weqaar commented 5 years ago

Understandable, only if possible I would like to merge your changes/additions in libflir, I can put in the effort for this.

Please let me know if there is any possibility otherwise no worries at all.

Thanks,

Weqaar A. Janjua

On Mon, 15 Apr 2019 at 21:38, JC Lee notifications@github.com wrote:

Yeah I think that would be really constructive, but there are a few hurdles...

I'll have to ask my boss about it

I'm reviewing the code and it feels large and kinda messy. At first glance, I don't think it'll merge nicely with yours even though the core of it is fairly similar.

PS I've been looking at @Aelphy https://github.com/Aelphy and his python code. Its footprint is quite small and so I'd like to look into that as well.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/weqaar/libflir/issues/1#issuecomment-483409348, or mute the thread https://github.com/notifications/unsubscribe-auth/ACo3YV1udNuFbeuQSN8tGD2tIpYe0Gikks5vhONXgaJpZM4R_OJe .