weqaar / libflir

Python FLIR API
MIT License
5 stars 2 forks source link

Question on libflir usage #2

Open vegetableclean opened 5 years ago

vegetableclean commented 5 years ago

Hi! I am a student who needs to do a project with flir TAU 2 to detect temperature in python. I am wondering if is there any possible to use libflir to do with TAU 2? And, is there any actual examples or reference code(even very simple) that can directly run on the PC? I think I really need some simple codes (I am a beginner) and I can learn by the code or revise the code to do my actual work. I have read the code of libflir but I still did not know how to command what I want (like detect temperature) or even to communicate with flir.(although I have read the flir reference book and know what bytes I should input) I just know about a little like I need to use pyserial to communicate with my flir port and then read the port and write,etc.. So, I think it will be very helpful to have some learning examples to help understanding. BTW, I have searched for lots of code related to Flir but I cannot find any simple codes that can run directly(I mean like a basic guide book, and sometimes even it has simple codes in it to help learning), so this is really tough for beginner like me.

Thanks!

vegetableclean commented 5 years ago

Also I have read your reply on issue https://github.com/weqaar/libflir/issues/1 Can you explain the function Serial_Functions_FLIR class for more details? What we will really get from it and what is the meaning of Parser_Functions() and .getSectionOption and others,and how to construct the whole process. Thanks!

weqaar commented 5 years ago

Hello,

I have added few source files that includes the classes and methods referenced in this issue.

Pull the updated sources, edit the conf file to suit your environment.

You will need to include these in the calling .py:

from serial_FLIR import *
from configInit import *
from libflir import *

Then initialize the class this way, perhaps in the main .py:

_libFLIR_object = FLIR_Functions()
_serial_FLIR_object = Serial_Functions_FLIR()
_serial_FLIR_object.serial_init_FLIR()

FLIR_queue_ingress = multiprocessing.Queue()
FLIR_queue_egress = multiprocessing.Queue()

Supposing you get the commands for FLIR in a queue, you may (there are many approaches):

RECEIVER

cmd = FLIR_queue_ingress.get()
(x, y) = getattr(_libFLIR_object, _cmd)()

if x is not False:
    _serial_FLIR_object.serial_write(x)
    FLIR_queue_egress.put(_serial_FLIR_object.serial_read(y))

I send these two commands for temperature unit setting and display in the queue from a UDP socket:

SENDER

_send_cmd_FLIR("set_spot_meter_F")
_send_cmd_FLIR("set_spot_display_thermometer")

Note that these parameters are function names from libflir.py - this mimics the way RPC works if you are familiar with it.

Hope this helps.

vegetableclean commented 5 years ago

Thank for your response. It will be a big help! BTW, what is the function of _send_cmd_FLIR ("set_spot_display_thermometer"), Does that have to define by myself?
like this ? def init(self): global _send_cmd_FLIR _send_cmd_FLIR = FLIR_Functions()

weqaar commented 5 years ago

_send_cmd_FLIR ("set_spot_display_thermometer") is an example of sending commands from a remotely connected controller/client, there are many ways i.e. you may just call this function set_spot_meter_F() from libflir that writes a command to Serial, look into the code.

vegetableclean commented 5 years ago

ok ,thanks a lot ! appreciate !

vegetableclean commented 5 years ago

Hi, Sorry for more question. Just want to make sure that I did understand your meaning. Do you mean that If I want to receive the center temperature,

The Process of physical meaning is to give the queue and write (sending the command) in a serial and then give a queue again and then receive my data from the serial?

So first, I can get the function from libflir like set_spot_display_thermometer and set_spot_meter_F(), like

SEND

_libFLIR_object = FLIR_Functions() #define function get_set_spot_display_thermometer=_libFLIR_object.set_spot_display_thermometer

to define set_spot_display_thermometer function

get_set_spot_meter_F=_libFLIR_object.set_spot_meter_F

to define set_spot_meter_F function

and to Receive their " cmd_ ", so I can use like your method:

RECEIVER

cmd = FLIR_queue_ingress.get() #did not know what its meaning, get a queue and called cmd(?) (x, y) = getattr(_libFLIR_object, _cmd)()

if x is not False: _serial_FLIR_object.serialwrite(x) #here I can write cmd to serial FLIR_queue_egress.put(_serial_FLIR_object.serial_read(y))

here I can read figures of temperature from serial

x aims to get their cmd_ while y aims to get their _bytes, but I have a little confuse, and I was wondering how does this "getattr(_libFLIR_object, _cmd)() " can receive my sending , should I replace the "_libFLIR_object ",and "_cmd " with anyrhing else like set_spot_meter_F or set_spot_display_thermometer , or I think maybe it will not get my command.

I don't know if my understanding is right. Sorry for too much stupid question.