Welcome, Guest
Username: Password: Remember me

TOPIC: PyRadmon install and set up on Raspberry Pi (Wheezy Raspbian)

PyRadmon install and set up on Raspberry Pi (Wheezy Raspbian) 2 years 8 months ago #772

  • jnissen
  • jnissen's Avatar
  • OFFLINE
  • Senior Member
  • Posts: 56
  • Thank you received: 11
  • Karma: 4
OK it's acting a bit strange. Not sure but I can run it consecutive times and get different responses for the detector model. See below:
Reading configuration:

User name configured

Password configured

Serial port name configured

Serial port speed configured

Protocol configured

Protocol configured


Using GMC protocol for 1 => geiger 1

No samples in queue, waiting 5 seconds => geiger 1

Gathering data started => geiger 1

Initializing GMC protocol communication => geiger 1

Found GMC-compatible device, version => geiger 1: GMC-300Re 2.36�

Please note data will be acquired once per 5 seconds => geiger 1

Unit shows time as => geiger 1: �


Problem in getData procedure (disconnected USB device?) => geiger 1:
local variable 'i' referenced before assignment
Exiting

Waiting and reap threads


You can see the special characters at the end of the line seem to be interpreted correctly depending on how many times I run it. Sometimes looks OK other times not.
The administrator has disabled public write access.

PyRadmon install and set up on Raspberry Pi (Wheezy Raspbian) 2 years 8 months ago #774

  • ThibmoRozier
  • ThibmoRozier's Avatar
  • OFFLINE
  • Elite Member
  • Posts: 182
  • Thank you received: 29
  • Karma: 9
jnissen wrote:
OK it's acting a bit strange. Not sure but I can run it consecutive times and get different responses for the detector model. See below:
Reading configuration:

User name configured

Password configured

Serial port name configured

Serial port speed configured

Protocol configured

Protocol configured


Using GMC protocol for 1 => geiger 1

No samples in queue, waiting 5 seconds => geiger 1

Gathering data started => geiger 1

Initializing GMC protocol communication => geiger 1

Found GMC-compatible device, version => geiger 1: GMC-300Re 2.36�

Please note data will be acquired once per 5 seconds => geiger 1

Unit shows time as => geiger 1: �


Problem in getData procedure (disconnected USB device?) => geiger 1:
local variable 'i' referenced before assignment
Exiting

Waiting and reap threads


You can see the special characters at the end of the line seem to be interpreted correctly depending on how many times I run it. Sometimes looks OK other times not.

Hmm... Oke...
I'll see what I can do about that. :)
The administrator has disabled public write access.

PyRadmon install and set up on Raspberry Pi (Wheezy Raspbian) 2 years 8 months ago #775

  • jnissen
  • jnissen's Avatar
  • OFFLINE
  • Senior Member
  • Posts: 56
  • Thank you received: 11
  • Karma: 4
I'm going to move on to another detector at this point. I tried a number of alternatives as well as your Pyradmon software and it seems the trouble is with some dropped bits at 56KBaud and the PL2303 driver. I tried to communicate with an alternative device that uses this same chip and if the baud rate is reasonable (like 19K or below) it seems to work just fine with the BBB. At this point I will try to sell my GMC-300 fixed baud unit and see if I can get a GMC-320+ with programmable baud rate. If there were a Wifi enabled unit I would go with that! My goal was to place the unit outside and WiFi communicate with it.
The administrator has disabled public write access.

PyRadmon install and set up on Raspberry Pi (Wheezy Raspbian) 2 years 8 months ago #776

  • ThibmoRozier
  • ThibmoRozier's Avatar
  • OFFLINE
  • Elite Member
  • Posts: 182
  • Thank you received: 29
  • Karma: 9
jnissen wrote:
I'm going to move on to another detector at this point. I tried a number of alternatives as well as your Pyradmon software and it seems the trouble is with some dropped bits at 56KBaud and the PL2303 driver. I tried to communicate with an alternative device that uses this same chip and if the baud rate is reasonable (like 19K or below) it seems to work just fine with the BBB. At this point I will try to sell my GMC-300 fixed baud unit and see if I can get a GMC-320+ with programmable baud rate. If there were a Wifi enabled unit I would go with that! My goal was to place the unit outside and WiFi communicate with it.
Welll... Please do try one last thing(For future users?)

I now have a little bit of debugging going on. :)
class gmc(baseGeigerCommunication):

    def initCommunication(self):
        print "Initializing GMC protocol communication => geiger 1\r\n"
        # get firmware version
        response=self.sendCommand("< GETVER >>")

        if len(response)>0:
            print "Found GMC-compatible device, version => geiger 1: ", response, "\r\n"
            # get serial number
            # serialnum=self.sendCommand("<GETSERIAL>>")
            # serialnum.int=struct.unpack('!1H', serialnum(7))[0]
            # print "Device Serial Number is: ", serialnum.int
            # disable heartbeat, we will request data from script
            self.sendCommand("< HEARTBEAT0 >>")
            print "Please note data will be acquired once per 5 seconds => geiger 1\r\n"
            # update the device time
            unitTime=self.sendCommand("< GETDATETIME >>")
            time.sleep(0.5)# just to ensure all CPM bytes are in serial port buffer
            print "Unit shows time as => geiger 1: ", unitTime, "\r\n"
            # self.sendCommand("<SETDATETIME[" + time.strftime("%y%m%d%H%M%S") + "]>>")
            # print "<SETDATETIME[" + time.strftime("%y%m%d%H%M%S") + "]>>"

        else:
            print "No response from device => geiger 1\r\n"
            self.stop()
            sys.exit(1)

    def getData(self):
        cpm=-1
            
        try:
            # wait, we want sample every 30s
            for i in range(0,3):
                time.sleep(1)

            # send request
            response=self.sendCommand("< GETCPM >>")
            # wait for data
            time.sleep(0.5) # just to ensure all CPM bytes are in serial port buffer

            if len(response)==2:
                # convert bytes to 16 bit int
                cpm=cpm + ord(response[0])*256+ord(response[1])
            else:
                edata=""
                for i in range(1,len(response)):
                    edata = edata + ord(response[0])*256+ord(response[i])
                print "Unknown response to CPM request, device is not GMC-compatible? => geiger 1\r\n"
                print "Data recieved was: ",str(edata),"\r\n"

        except Exception as e:
            print "\r\nProblem in getData procedure (disconnected USB device?) => geiger 1:\r\n\t",str(e),"\r\nExiting\r\n"
            self.stop()
            sys.exit(1)
            
        utcTime=datetime.datetime.utcnow()
        data=[cpm, utcTime]
        return data

Oh and perhaps, you should try the geiger counter made by Dan.
It should work just fine with PyRadmon. :O
Last Edit: 2 years 8 months ago by ThibmoRozier.
The administrator has disabled public write access.

PyRadmon install and set up on Raspberry Pi (Wheezy Raspbian) 2 years 8 months ago #777

  • jnissen
  • jnissen's Avatar
  • OFFLINE
  • Senior Member
  • Posts: 56
  • Thank you received: 11
  • Karma: 4
Humm well it's been running about seven minutes... fingers crossed.

It did report this but still works...

Data recieved was:

Geiger sample => geiger 1: CPM = -1 2015-03-01 03:58:44.750654
Geiger sample => geiger 1: CPM = 12 2015-03-01 03:58:48.758551
Geiger sample => geiger 1: CPM = 13 2015-03-01 03:58:52.768874


Never saw it report that before. it seems to keep running and the average is only slightly lower as a result. Perhaps the thing was never responding to the request at times? I will let it run and see how it does.


UPDATE:
About 20 minutes so far. I do see errors, but it gets through them.

Geiger sample => geiger 1: CPM = 15 2015-03-01 03:57:16.496798
Geiger sample => geiger 1: CPM = 13 2015-03-01 03:57:20.506366
Geiger sample => geiger 1: CPM = 15 2015-03-01 03:57:24.518782
Geiger sample => geiger 1: CPM = 15 2015-03-01 03:57:28.529968
Unknown response to CPM request, device is not GMC-compatible? => geiger 1

Data recieved was:

Geiger sample => geiger 1: CPM = -1 2015-03-01 03:57:32.544654
Unknown response to CPM request, device is not GMC-compatible? => geiger 1

Data recieved was:

Geiger sample => geiger 1: CPM = -1 2015-03-01 03:57:36.558507
Geiger sample => geiger 1: CPM = 18 2015-03-01 03:57:40.567113
Average result => geiger 1: CPM = 11 2015-03-01 03:57:40.567113

Connecting to server => geiger 1

Sending average sample => geiger 1: 11 CPM

Server response => geiger 1: HTTP/1.1 200 OK

Waiting 30 seconds => geiger 1

Geiger sample => geiger 1: CPM = 17 2015-03-01 03:57:44.578701
Unknown response to CPM request, device is not GMC-compatible? => geiger 1

Data recieved was:

Geiger sample => geiger 1: CPM = -1 2015-03-01 03:57:48.592302
Geiger sample => geiger 1: CPM = 20 2015-03-01 03:57:52.601759
Geiger sample => geiger 1: CPM = 19 2015-03-01 03:57:56.612825
Geiger sample => geiger 1: CPM = 20 2015-03-01 03:58:00.624583
Geiger sample => geiger 1: CPM = 22 2015-03-01 03:58:04.635998
Geiger sample => geiger 1: CPM = 22 2015-03-01 03:58:08.647235
Geiger sample => geiger 1: CPM = 20 2015-03-01 03:58:12.658822
Average result => geiger 1: CPM = 17 2015-03-01 03:58:12.658822

Connecting to server => geiger 1

Sending average sample => geiger 1: 17 CPM

Server response => geiger 1: HTTP/1.1 200 OK

Waiting 30 seconds => geiger 1

Geiger sample => geiger 1: CPM = 20 2015-03-01 03:58:16.670564
Geiger sample => geiger 1: CPM = 21 2015-03-01 03:58:20.680302
Geiger sample => geiger 1: CPM = 18 2015-03-01 03:58:24.691723
Geiger sample => geiger 1: CPM = 20 2015-03-01 03:58:28.702770
Geiger sample => geiger 1: CPM = 17 2015-03-01 03:58:32.713823
Unknown response to CPM request, device is not GMC-compatible? => geiger 1


This was the worst of it. Most of the transactions are normal but for whatever reason the above it was going crazy with errors every few seconds. I will let it run all night and see if the website map is updating. I will let you all know how it goes.
Last Edit: 2 years 8 months ago by jnissen.
The administrator has disabled public write access.

PyRadmon install and set up on Raspberry Pi (Wheezy Raspbian) 2 years 8 months ago #779

  • ThibmoRozier
  • ThibmoRozier's Avatar
  • OFFLINE
  • Elite Member
  • Posts: 182
  • Thank you received: 29
  • Karma: 9
At least it's something... Now I have to work with that data...
So it seems to not enjoy the method of sending data...
The retrieval is even worse... Gosh.
It keeps giving data waaaay too much.. :/
Every 4 seconds it seems... How does your class Main look like?

//EDIT:
@Dan, could you please show how you managed to fix this, I am starting to get a headache. :/
I really want to fix this issue.

Then a little try from my side... To bypass the sendCommand definition...

The GMC class:
class gmc(baseGeigerCommunication):

    def initCommunication(self):
        print "Initializing GMC protocol communication => geiger 1\r\n"
        # get firmware version
        self.serialPort.flushInput()
        self.serialPort.write("< GETVER >>")
        # assume that device responds within 1s
        time.sleep(1)
        response=""
        while (self.serialPort.inWaiting()>0 and self.stopwork==0):
            response = response + self.serialPort.read()
        # response=self.sendCommand("< GETVER >>")

        if len(response)>0:
            print "Found GMC-compatible device, version => geiger 1: ", response, "\r\n"
            # get serial number
            # serialnum=self.sendCommand("<GETSERIAL>>")
            # serialnum.int=struct.unpack('!1H', serialnum(7))[0]
            # print "Device Serial Number is: ", serialnum.int
            # disable heartbeat, we will request data from script
            self.serialPort.flushInput()
            self.serialPort.write("< HEARTBEAT0 >>")
            # self.sendCommand("< HEARTBEAT0 >>")
            print "Please note data will be acquired once per 5 seconds => geiger 1\r\n"
            # update the device time
            self.serialPort.flushInput()
            self.serialPort.write("< GETDATETIME >>")
            # assume that device responds within 1s
            time.sleep(1)
            response=""
            while (self.serialPort.inWaiting()>0 and self.stopwork==0):
                unitTime = unitTime + self.serialPort.read()
            # unitTime=self.sendCommand("< GETDATETIME >>")
            time.sleep(0.5)# just to ensure all CPM bytes are in serial port buffer
            print "Unit shows time as => geiger 1: ", unitTime, "\r\n"
            # self.sendCommand("<SETDATETIME[" + time.strftime("%y%m%d%H%M%S") + "]>>")
            # print "<SETDATETIME[" + time.strftime("%y%m%d%H%M%S") + "]>>"

        else:
            print "No response from device => geiger 1\r\n"
            self.stop()
            sys.exit(1)

    def getData(self):
        cpm=-1
            
        try:
            # wait, we want sample every 30s
            for i in range(0,3):
                time.sleep(1)

            # send request
            self.serialPort.flushInput()
            self.serialPort.write("< GETCPM >>")
            # assume that device responds within 1s
            time.sleep(1)
            response=""
            while (self.serialPort.inWaiting()>0 and self.stopwork==0):
                response = response + self.serialPort.read()
            # response=self.sendCommand("< GETCPM >>")
            # wait for data
            time.sleep(0.5) # just to ensure all CPM bytes are in serial port buffer

            if len(response)==2:
                # convert bytes to 16 bit int
                cpm = cpm + ord(response[0])*256+ord(response[1])
            elif len(response) > 2:
                edata=""
                for i in range(1,len(response)):
                    edata = edata + ord(response[0])*256+ord(response[i])
                cpm = int( ( float(cpm) / ( len(response) - 1 ) ) +0.5)
            else:
                edata=""
                for i in range(1,len(response)):
                    edata = edata + ord(response[0])*256+ord(response[i])
                print "Unknown response to CPM request, device is not GMC-compatible? => geiger 1\r\n"
                print "Data recieved was: ",str(edata),"\r\n"

        except Exception as e:
            print "\r\nProblem in getData procedure (disconnected USB device?) => geiger 1:\r\n\t",str(e),"\r\nExiting\r\n"
            self.stop()
            sys.exit(1)
            
        utcTime=datetime.datetime.utcnow()
        data=[cpm, utcTime]
        return data

The Main class(//NOTE I changed "def" to "class"):
class main():
    # main loop is in while loop
    # check if file exists, if not, create one and exit
    if (os.path.isfile("config.txt")==0):
        print "\tNo configuration file, creating default one.\r\n\t"

        try:
            f = open("config.txt", 'w')
            f.write("# Parameter names are not case-sensitive\r\n")
            f.write("# Parameter values are case-sensitive\r\n")
            f.write("user=test_user\r\n")
            f.write("password=test_password\r\n")
            f.write("# Port is usually /dev/ttyUSBx in Linux and COMx in Windows\r\n")
            f.write("serialport=/dev/ttyUSB0\r\n")
            f.write("speed=2400\r\n")
            f.write("# Protocols: demo, mygeiger, gmc, netio, audio\r\n")
            f.write("protocol=demo\r\n")
            f.write("# In case of audio, input the device number here, default is 0.\r\n")
            p = pyaudio.PyAudio()
            info = p.get_host_api_info_by_index(0)
            #for each audio device, determine if is an input or an output and add it to the appropriate list and dictionary
            for i in range (0,info.get('deviceCount')):
                if p.get_device_info_by_host_api_device_index(0,i).get('maxInputChannels')>0:
                    f.write("# %d - %s \r\n"%(i,p.get_device_info_by_host_api_device_index(0,i).get('name')))
            f.write("device=0\r\n")
            print "\tPlease open config.txt file using text editor and update configuration.\r\n"
        except Exception as e:
            print "\tFailed to create configuration file\r\n\t",str(e)
        finally:
            time.sleep(1)
            p.terminate()
            f.close()
        sys.exit(1)
    else:
        # create and read configuration data
        cfg=config()
        cfg.readConfig()
        # create geiger communication object
        if cfg.protocol==config.MYGEIGER:
            print "Using myGeiger protocol for 1 => geiger 1\r\n"
            geigerCommunication=myGeiger(cfg)
        elif cfg.protocol==config.DEMO:
            print "Using Demo mode for 1 => geiger 1\r\n"
            geigerCommunication=Demo(cfg)
        elif cfg.protocol==config.GMC:
            print "Using GMC protocol for 1 => geiger 1\r\n"
            geigerCommunication=gmc(cfg)
        elif cfg.protocol==config.NETIO:
            print "Using NetIO protocol for 1 => geiger 1\r\n"
            geigerCommunication=netio(cfg)
        elif cfg.protocol==config.AUDIO:
            print "Using audio protocol for 1 => geiger 1\r\n"
            geigerCommunication = audioCommunication(cfg)
        else:
            print "Unknown protocol configured, can't run => geiger 1\r\n"
            sys.exit(1)

        try:
            # create web server communication object
            webService=webCommunication(cfg)

            # start measuring thread
            geigerCommunication.start()

            # Now send data to web site every 30 seconds
            while(geigerCommunication.is_running==1):
                sample=geigerCommunication.getResult()

                if sample[0]!=-1:
                    # sample is valid, CPM !=-1
                    print "Average result => geiger 1:\tCPM =",sample[0],"\t",str(sample[1]),"\r\n"
                    try:
                        webService.sendSample(sample)
                    except Exception as e:
                        print "Error communicating server => geiger 1:\r\n\t", str(e),"\r\n"

                    print "Waiting 30 seconds => geiger 1\r\n"
                    # Waiting 60x0.5 seconds,
                    # it has a better response when CTRL+C is used,
                    # might be changed in future
                    for i in range(0,60):
                        time.sleep(0.5)
                else:
                    print "No samples in queue, waiting 5 seconds => geiger 1\r\n"
                    for i in range(0,5):
                        time.sleep(1)
                    continue

        except KeyboardInterrupt as e:
            print "\r\nCTRL+C pressed, exiting program\r\n\t", str(e), "\r\n"

        except SystemExit:
            print "\r\nSystem exit\r\n\t",str(e),"\r\n"

        except Exception as e:
            print "\r\nUnhandled error\r\n\t",str(e),"\r\n"

        geigerCommunication.stop()

        # Threading fix
        print "Waiting and reap threads"
        time.sleep(1)
        for numThread in threading.enumerate():
            if numThread.isDaemon(): continue
            if numThread.getName() == 'MainThread': continue
            print "Stopping alive thread: ", numThread.getName(), "\r\n\t"
            numThread.stop()
            time.sleep(1)
        sys.exit(0)

if __name__ == '__main__':
    main()
Last Edit: 2 years 8 months ago by ThibmoRozier.
The administrator has disabled public write access.
Time to create page: 0.221 seconds
Powered by Kunena Forum