I have a power meter. It's a currencost envi (alias cc128), see here for details : http://www.currentcost.com/product-cc128.html
This power meter as a serial connection to output some data. Details of the data sent are there :
It's really simple, there is nothing to write to the serail port, we just have to read the serial port.
When I got this device I wrote a small C# program to write down to files every bytes this device outputs. It has been really simple: one cc128 class with a serial port in it and a receive event that writes received data to files. After that, I have extended the C# prog to send event to eventghost based on the real time power consuption reported by the cc128.
I simply launch eg withe the -e cmd param from the c# prog.
Now, I think that it would be better to have an eg plugin to manage the data sent by this device.
So I searched a bit, I found this :
http://www.eventghost.org/docs/eg/eg.Se ... rialThread
And have explored a few other plugins that seem to read data from a serial port.
At this point, the project seems to me really simple. I quickly wrote something like this :
Code: Select all
eg.RegisterPlugin( name = "CC128", author = "miljbee+egCC128@gmail.com", version = "0.0.1", kind = "other", description = "This plugin generates events from the serial interface of the CC128. The CC128 is a power monitor. More info here : http://www.currentcost.com/product-cc128.html" ) class CC128Plugin(eg.PluginBase): def __init__(self,port): self.port=port self.serialThread=None def __start__(self,port): self.port=port self.serialThread=eg.SerialThread() self.serialThread.SetReadEventCallback(self.OnReceive) self.serialThread.Open(port, 57600,'8N1') self.serialThread.Start() def __stop__(self): self.serialThread.Stop() def __close__(self): self.serialThread.Stop() def Configure(self, port=0): panel = eg.ConfigPanel(self) portCtrl = panel.SerialPortChoice(port) panel.AddLine("Port:", portCtrl) while panel.Affirmed(): panel.SetResult(portCtrl.GetValue()) def OnReceive(self, serial): buffer = "" while True: b = serial.Read(1, 0.1) if b == "\n": break buffer+=b [b]print buffer[/b] #Process the received data block stored in the buffer
the buffer gets filled with data, but not all chars send by the device are in the buffer. Further more, it seems that they are not in the order they are sent by the device.
as an exemple, if I expect to receive something like :
the buffer might contain something like :
I am pretty sure I am missing something evident, but I can't get it. Also, note that I am new to python.
I have also tried the generic serial plugin, and it works out of the box. I won't use it, because I don't want to generate events each time I receive a data block.
Any help would be greatly appreciated.