Read data from SQM-LU device
-
- Posts: 275
- Joined: 10 Dec 2018, 16:23
Read data from SQM-LU device
Hi newbie here so gentle please.
I have Astroart 6 with SP2 and using Camera Control 6 and 6.2 beta.
I am on a steep learning curve with my newly aquired telescopes/mounts etc.
As an aside (I used to work in Automation/MES in the pharmaceutical industry as a software developer - now retired)
I thought I will have a go at a plugin for astroart which would involve sky quality visualisation and integration with imaging etc
As a feasability study I started with scripting as below; this is not my original as I have already had some emial correspondance re this issue.
conn = Serial.Connect(6)
Pause(0.2)
if not conn then Message("Port 6 not Connected.")
rem if conn then Message("Port 6 Connected.")
Serial.Send("rx" )
rem + Chr(13) + Chr(10))
retstring = Serial.Receive$()
Print("-->" + retstring + "<--")
Serial.Disconnect()
Print("End")
I get no errors with this script but I also get no return string - I know SQL reader works as supplied for the SQL-LU device.
I believe there is no need to add CR or LF at end of read request - but this may be incorrect although I have tried all possible variations
I am assuming as the SQM device is on com6 in device manager that 6 is the correct number to connect too.
Anybody got any input that could help me here - first suggestion is the com port settings but am unaware if there is a Serial.baudrate method associated with the scripting command
thanks for any suggestions
I have Astroart 6 with SP2 and using Camera Control 6 and 6.2 beta.
I am on a steep learning curve with my newly aquired telescopes/mounts etc.
As an aside (I used to work in Automation/MES in the pharmaceutical industry as a software developer - now retired)
I thought I will have a go at a plugin for astroart which would involve sky quality visualisation and integration with imaging etc
As a feasability study I started with scripting as below; this is not my original as I have already had some emial correspondance re this issue.
conn = Serial.Connect(6)
Pause(0.2)
if not conn then Message("Port 6 not Connected.")
rem if conn then Message("Port 6 Connected.")
Serial.Send("rx" )
rem + Chr(13) + Chr(10))
retstring = Serial.Receive$()
Print("-->" + retstring + "<--")
Serial.Disconnect()
Print("End")
I get no errors with this script but I also get no return string - I know SQL reader works as supplied for the SQL-LU device.
I believe there is no need to add CR or LF at end of read request - but this may be incorrect although I have tried all possible variations
I am assuming as the SQM device is on com6 in device manager that 6 is the correct number to connect too.
Anybody got any input that could help me here - first suggestion is the com port settings but am unaware if there is a Serial.baudrate method associated with the scripting command
thanks for any suggestions
-
- Posts: 275
- Joined: 10 Dec 2018, 16:23
Re: Read data from SQM-LU device
Hello, something I would try:
1) Connect to the hardware using a serial port terminal (for example: PuTTY) and verify the connection:
https://www.youtube.com/watch?v=dO-BMOzNKcI
2) Place a Pause between .Send and .Receive (the pause after Connect is not needed).
3) Check if the hardware supports 9600 baud 8N1.
1) Connect to the hardware using a serial port terminal (for example: PuTTY) and verify the connection:
https://www.youtube.com/watch?v=dO-BMOzNKcI
2) Place a Pause between .Send and .Receive (the pause after Connect is not needed).
3) Check if the hardware supports 9600 baud 8N1.
-
- Posts: 275
- Joined: 10 Dec 2018, 16:23
Re: Read data from SQM-LU device
Hi
Thanks for the reply I will what you have suggested asap
I think from a previous reply from the SQM guys that I cannot change the port settings but will investigate that and confirm
I also think this is some info that the "port controller" manages the port settings but again it is not proven
Onwards and upwards - I hope
Thanks for the reply I will what you have suggested asap
I think from a previous reply from the SQM guys that I cannot change the port settings but will investigate that and confirm
I also think this is some info that the "port controller" manages the port settings but again it is not proven
Onwards and upwards - I hope
-
- Posts: 275
- Joined: 10 Dec 2018, 16:23
Re: Read data from SQM-LU device
sub WaitForOutput()
tx = 0
While rx = "" and tx < timeout
rx = Serial.Recieve()
Pause(1)
tx = tx +1
End while
End sub
You need to wait for the reply to come back due to the time the internal chip takes to average the readings.
So add a wait for reply subroutine like the above after sending the message.
Also it looks like you need to set the port to 115200 rate.
Example perl script
#!/usr/bin/perl
#Filename: read-sqmlu.pl
#Description: Utility to read Unihedron Sky Quality Meter-LU (USB model)
# Define the required module
use Device::SerialPort;
# Open and configure serial port
$port= Device::SerialPort->new("/dev/ttyUSB2");
$port->user_msg(ON);
$port->baudrate(115200);
$port->parity("none");
$port->stopbits(1);
$port->databits(8);
$port->handshake("none");
$port->write_settings || undef $port;
$port->read_char_time(1); # Wait for each character
# Send request to SQM
$port->write("rx\r");
# Get response from SQM
($count,$saw)=$port->read(255);
# Close the port so that other programs can use the SQM
$port->close;
So maybe you need to write an interface that just passes the data to AA6.
The above should be possible from the script commands. But try setting the port to 115200 first.
Regards,
John
tx = 0
While rx = "" and tx < timeout
rx = Serial.Recieve()
Pause(1)
tx = tx +1
End while
End sub
You need to wait for the reply to come back due to the time the internal chip takes to average the readings.
So add a wait for reply subroutine like the above after sending the message.
Also it looks like you need to set the port to 115200 rate.
Example perl script
#!/usr/bin/perl
#Filename: read-sqmlu.pl
#Description: Utility to read Unihedron Sky Quality Meter-LU (USB model)
# Define the required module
use Device::SerialPort;
# Open and configure serial port
$port= Device::SerialPort->new("/dev/ttyUSB2");
$port->user_msg(ON);
$port->baudrate(115200);
$port->parity("none");
$port->stopbits(1);
$port->databits(8);
$port->handshake("none");
$port->write_settings || undef $port;
$port->read_char_time(1); # Wait for each character
# Send request to SQM
$port->write("rx\r");
# Get response from SQM
($count,$saw)=$port->read(255);
# Close the port so that other programs can use the SQM
$port->close;
So maybe you need to write an interface that just passes the data to AA6.
The above should be possible from the script commands. But try setting the port to 115200 first.
Regards,
John
-
- Posts: 275
- Joined: 10 Dec 2018, 16:23
Re: Read data from SQM-LU device
Hi all
have tried all as requested and not got anywhere
I think this maybe something to do with port settings - I had a reply from the unihedron guys the gist of which is below
"It would be much better to have the Astorart script set the baud rate to
115200, because if the SQM is set to 9600, then other programs will not
be able to communicate with it (like UDM).
I used the device manager to set the baud rate of the COM port to 115200,
but the AStroart script did not recognize that, so it seems that it is
fixed inside AStroart.
Let me know how it goes with Astroart. If they cannot allow a baud rate
change, then I will work on a firmware upgrade that allows baud rate
changes or something with a fixed 9600 baud rate."
So is there anyway I can do a command within the astroart script like the perl scipt command $port->baudrate(115200);
cheers Keith
have tried all as requested and not got anywhere
I think this maybe something to do with port settings - I had a reply from the unihedron guys the gist of which is below
"It would be much better to have the Astorart script set the baud rate to
115200, because if the SQM is set to 9600, then other programs will not
be able to communicate with it (like UDM).
I used the device manager to set the baud rate of the COM port to 115200,
but the AStroart script did not recognize that, so it seems that it is
fixed inside AStroart.
Let me know how it goes with Astroart. If they cannot allow a baud rate
change, then I will work on a firmware upgrade that allows baud rate
changes or something with a fixed 9600 baud rate."
So is there anyway I can do a command within the astroart script like the perl scipt command $port->baudrate(115200);
cheers Keith
-
- Posts: 275
- Joined: 10 Dec 2018, 16:23
Re: Read data from SQM-LU device
If all else fails Keith and the simple solution of changing the baud rate within an AA6 script is not easy, I will write an exe that you can run using :
System.Execute("scripts\Sqm.exe rx reply.txt")
Bit like the PHD2 guiding interface.
You could also mess about with the commands...
sqmcmd = "ix"
System.Execute("scripts\Sqm.exe "+sqmcmd+ "reply.txt")
This code will wait for a response and then write it to a text file in your home directory or maybe even a variable in AA6.
I can simulate the SQM with an Arduino and then you could do the final testing. Or I could come over to Worthing..
All the best
John
System.Execute("scripts\Sqm.exe rx reply.txt")
Bit like the PHD2 guiding interface.
You could also mess about with the commands...
sqmcmd = "ix"
System.Execute("scripts\Sqm.exe "+sqmcmd+ "reply.txt")
This code will wait for a response and then write it to a text file in your home directory or maybe even a variable in AA6.
I can simulate the SQM with an Arduino and then you could do the final testing. Or I could come over to Worthing..
All the best
John
-
- Posts: 275
- Joined: 10 Dec 2018, 16:23
Re: Read data from SQM-LU device
Fabio,
The SQM runs at a baud of 115200, Is there a way to change AA6 *serial.send/receive to work at another baud rate?
Regards
The SQM runs at a baud of 115200, Is there a way to change AA6 *serial.send/receive to work at another baud rate?
Regards
-
- Posts: 275
- Joined: 10 Dec 2018, 16:23
Re: Read data from SQM-LU device
Yes, the option has been added to scripts today. It will be released with the Service Pack 3 next autumn. To receive a prerelease please contact me by email.
Fabio.
Fabio.
-
- Posts: 275
- Joined: 10 Dec 2018, 16:23
Re: Read data from SQM-LU device
Fabio - yes I would be interested in the prerelease and will contact you by private message.
Can I add that I have taken another tack which does not negate my interest in the port connection route; this involves reading a text file.
I will post my script when I fine tune it - but basically it takes the text file created by the SQM device and reads the latest value then converts it to a Bortle value - as I mentioned previusly I would like to create a plug-in which deals with sky quality in real time so actions can be taken when it becomes poor - anyway thats the dream
many thanks
Keith
Can I add that I have taken another tack which does not negate my interest in the port connection route; this involves reading a text file.
I will post my script when I fine tune it - but basically it takes the text file created by the SQM device and reads the latest value then converts it to a Bortle value - as I mentioned previusly I would like to create a plug-in which deals with sky quality in real time so actions can be taken when it becomes poor - anyway thats the dream
many thanks
Keith
-
- Posts: 275
- Joined: 10 Dec 2018, 16:23
Re: Read data from SQM-LU device
Hi I can confirm the following script works based on the SP3 pre-release
CRET$ = Serial.Connect(6,115200)
if CRET$ = True Then
Message ("Port 6 Connected.")
else
Message ("Port 6 NOT Connected.")
endif
Serial.Send("rx" + chr(13))
Pause(1)
r$ = Serial.Receive$()
Print(r$)
Serial.Disconnect()
Print("End")
So issue was with setting port baud rate - this is great cos that is all I needed to do.
I will progress with the script now and base it on the one I have created below which works with SP2 - but needs tidying up
REM BORTLE Table from WIKI
REM Class Title NELM SQM
REM 1 Excellent dark-sky site 7.6-8.0 21.7-22.0
REM 2 Typical truly dark site 7.1-7.5 21.5-21.7
REM 3 Rural sky 6.6-7.0 21.3-21.5
REM 4 Rural/suburban transition 6.1-6.5 20.4-21.3
REM 5 Suberban sky 5.6-6.0 19.1-20.4
REM 6 Bright suburban sky 5.1-5.5 18.0-19.1
REM 7 Suburban/Urban transition 4.6-5.0 18.0-19.1
REM 8 City sky 4.1-4.5 <18
REM 9 Inner city sky 4.0 <18
FileToOpen = "C:\Users\Butterbelly\Documents\SQM Reader 2\SQMReadings.txt"
REM Print("Start")
CharCountForFile = 0
LineCount = 0
LinePrevious = 0
LineNow = 0
REM Read the File
SQMReadFile = opentext$(FileToOpen)
REM Get Number Characters in File
CharCountInFile = Len(SQMReadFile)
Rem Print LineCount
Rem Print SQMReadFile
REM Print FindPosLastLine
LineToExtract = mid$(SQMReadFile,FindPosLastLine,CharCountinFile)
Print ExtractData
REM Print "Data Extraction Complete-->"
REM Print "CV to -->",LineToExtract
REM Print " SQM -->",ExtractedSQM
REM Print " NELM -->",ExtractedNELM
REM Print " Temp -->",ExtractedTemp
Print GetBORTLEValue
REM Print("End")
sub GetBORTLEValue
BortleValue = "Undefined Sky"
if (val(ExtractedNELM) >= 7.5) then
BortleValue = "Class 1 --> " + "Excellent dark-sky site."
end if
if (val(ExtractedNELM) >= 7.1) and (val(ExtractedNELM) <= 7.5) then
BortleValue = "Class 2 --> " + "Typical truly dark site."
end if
if (val(ExtractedNELM) >= 6.6) and (val(ExtractedNELM) <= 7.0) then
BortleValue = "Class 3 --> " + "Rural sky."
end if
if (val(ExtractedNELM) >= 6.1) and (val(ExtractedNELM) <= 6.5) then
BortleValue = "Class 4 --> " + "Rural/suburban transition ."
end if
if (val(ExtractedNELM) >= 5.6) and (val(ExtractedNELM) <= 6.0) then
BortleValue = "Class 5 --> " + "Suberban sky."
end if
if (val(ExtractedNELM) >= 4.1) and (val(ExtractedNELM) <= 4.5) then
BortleValue = "Class 6 --> " + "City Sky."
end if
if (val(ExtractedNELM) >= 4.6) and (val(ExtractedNELM) <= 5.0) then
BortleValue = "Class 7 --> " + "Suburban/Urban transition."
end if
if (val(ExtractedNELM) >= 4.1) and (val(ExtractedNELM) <= 4.5) then
BortleValue = "Class 8 --> " + "City Sky."
end if
if val(ExtractedNELM) <= 4 then
BortleValue = "Class 9 --> " + "Inner City Sky."
end if
if val(ExtractedNELM) <= 0 then
BortleValue = "Probably DAYLIGHT at the moment.."
end if
return BortleValue
end sub
sub FindPosLastLine
CharCount = 0
while CharCount < CharCountInFile
if asc(SQMReadFile[CharCount]) = 13 then
LinePrevious = LineNow
LineNow = CharCount
end if
CharCount = CharCount + 1
end while
LastLinePos = LinePrevious + 1
Return LastLinePos
end sub
sub ExtractData
REM DateTime position = 1 and 2
REM SQM position = 3
REM NELM position = 4
REM Temp position = 9
FirstPos = 0
CharCount = 1
For cnt = 1 to 9
while LineToExtract[CharCount] <> "," then
REM print Charcount
SecondPos = CharCount + 1
CharCount = CharCount + 1
end while
SecondPos = (SecondPos - FirstPos)
REM print "Finished Loop" , secondpos
REM print mid$(LineToExtract,FirstPos+1,SecondPos-1)
If cnt = 3 then
ExtractedSQM = mid$(LineToExtract,FirstPos+1,SecondPos-1)
End If
If cnt = 4 then
ExtractedNELM = mid$(LineToExtract,FirstPos+1,SecondPos-1)
End If
If cnt = 9 then
ExtractedTemp = mid$(LineToExtract,FirstPos+1,SecondPos-1)
End If
FirstPos = (FirstPos + SecondPos)
REM print firstpos
REM print "Count --> ", cnt
REM print CharCount
CharCount = CharCount + 1
next cnt
Return "Data Extraction --> OK"
end sub
sub ExtractSQMValue
REM position = 3
FirstPos =22
SecondPos = 4
Return mid$(LineToExtract,FirstPos,SecondPos)
end sub
sub ExtractNELM
REM position = 4
FirstPos =27
SecondPos =4
Return mid$(LineToExtract,FirstPos,SecondPos)
end sub
sub ExtractTemp
REM position = 9
FirstPos =68
SecondPos =4
Return mid$(LineToExtract,FirstPos,SecondPos)
end sub
CRET$ = Serial.Connect(6,115200)
if CRET$ = True Then
Message ("Port 6 Connected.")
else
Message ("Port 6 NOT Connected.")
endif
Serial.Send("rx" + chr(13))
Pause(1)
r$ = Serial.Receive$()
Print(r$)
Serial.Disconnect()
Print("End")
So issue was with setting port baud rate - this is great cos that is all I needed to do.
I will progress with the script now and base it on the one I have created below which works with SP2 - but needs tidying up
REM BORTLE Table from WIKI
REM Class Title NELM SQM
REM 1 Excellent dark-sky site 7.6-8.0 21.7-22.0
REM 2 Typical truly dark site 7.1-7.5 21.5-21.7
REM 3 Rural sky 6.6-7.0 21.3-21.5
REM 4 Rural/suburban transition 6.1-6.5 20.4-21.3
REM 5 Suberban sky 5.6-6.0 19.1-20.4
REM 6 Bright suburban sky 5.1-5.5 18.0-19.1
REM 7 Suburban/Urban transition 4.6-5.0 18.0-19.1
REM 8 City sky 4.1-4.5 <18
REM 9 Inner city sky 4.0 <18
FileToOpen = "C:\Users\Butterbelly\Documents\SQM Reader 2\SQMReadings.txt"
REM Print("Start")
CharCountForFile = 0
LineCount = 0
LinePrevious = 0
LineNow = 0
REM Read the File
SQMReadFile = opentext$(FileToOpen)
REM Get Number Characters in File
CharCountInFile = Len(SQMReadFile)
Rem Print LineCount
Rem Print SQMReadFile
REM Print FindPosLastLine
LineToExtract = mid$(SQMReadFile,FindPosLastLine,CharCountinFile)
Print ExtractData
REM Print "Data Extraction Complete-->"
REM Print "CV to -->",LineToExtract
REM Print " SQM -->",ExtractedSQM
REM Print " NELM -->",ExtractedNELM
REM Print " Temp -->",ExtractedTemp
Print GetBORTLEValue
REM Print("End")
sub GetBORTLEValue
BortleValue = "Undefined Sky"
if (val(ExtractedNELM) >= 7.5) then
BortleValue = "Class 1 --> " + "Excellent dark-sky site."
end if
if (val(ExtractedNELM) >= 7.1) and (val(ExtractedNELM) <= 7.5) then
BortleValue = "Class 2 --> " + "Typical truly dark site."
end if
if (val(ExtractedNELM) >= 6.6) and (val(ExtractedNELM) <= 7.0) then
BortleValue = "Class 3 --> " + "Rural sky."
end if
if (val(ExtractedNELM) >= 6.1) and (val(ExtractedNELM) <= 6.5) then
BortleValue = "Class 4 --> " + "Rural/suburban transition ."
end if
if (val(ExtractedNELM) >= 5.6) and (val(ExtractedNELM) <= 6.0) then
BortleValue = "Class 5 --> " + "Suberban sky."
end if
if (val(ExtractedNELM) >= 4.1) and (val(ExtractedNELM) <= 4.5) then
BortleValue = "Class 6 --> " + "City Sky."
end if
if (val(ExtractedNELM) >= 4.6) and (val(ExtractedNELM) <= 5.0) then
BortleValue = "Class 7 --> " + "Suburban/Urban transition."
end if
if (val(ExtractedNELM) >= 4.1) and (val(ExtractedNELM) <= 4.5) then
BortleValue = "Class 8 --> " + "City Sky."
end if
if val(ExtractedNELM) <= 4 then
BortleValue = "Class 9 --> " + "Inner City Sky."
end if
if val(ExtractedNELM) <= 0 then
BortleValue = "Probably DAYLIGHT at the moment.."
end if
return BortleValue
end sub
sub FindPosLastLine
CharCount = 0
while CharCount < CharCountInFile
if asc(SQMReadFile[CharCount]) = 13 then
LinePrevious = LineNow
LineNow = CharCount
end if
CharCount = CharCount + 1
end while
LastLinePos = LinePrevious + 1
Return LastLinePos
end sub
sub ExtractData
REM DateTime position = 1 and 2
REM SQM position = 3
REM NELM position = 4
REM Temp position = 9
FirstPos = 0
CharCount = 1
For cnt = 1 to 9
while LineToExtract[CharCount] <> "," then
REM print Charcount
SecondPos = CharCount + 1
CharCount = CharCount + 1
end while
SecondPos = (SecondPos - FirstPos)
REM print "Finished Loop" , secondpos
REM print mid$(LineToExtract,FirstPos+1,SecondPos-1)
If cnt = 3 then
ExtractedSQM = mid$(LineToExtract,FirstPos+1,SecondPos-1)
End If
If cnt = 4 then
ExtractedNELM = mid$(LineToExtract,FirstPos+1,SecondPos-1)
End If
If cnt = 9 then
ExtractedTemp = mid$(LineToExtract,FirstPos+1,SecondPos-1)
End If
FirstPos = (FirstPos + SecondPos)
REM print firstpos
REM print "Count --> ", cnt
REM print CharCount
CharCount = CharCount + 1
next cnt
Return "Data Extraction --> OK"
end sub
sub ExtractSQMValue
REM position = 3
FirstPos =22
SecondPos = 4
Return mid$(LineToExtract,FirstPos,SecondPos)
end sub
sub ExtractNELM
REM position = 4
FirstPos =27
SecondPos =4
Return mid$(LineToExtract,FirstPos,SecondPos)
end sub
sub ExtractTemp
REM position = 9
FirstPos =68
SecondPos =4
Return mid$(LineToExtract,FirstPos,SecondPos)
end sub
-
- Posts: 275
- Joined: 10 Dec 2018, 16:23
Re: Read data from SQM-LU device
Hi,
I'm 18 months late here, but I run an SQM-LU, and read it it using my own little program written in Interactive Data Language (IDL), he language of professional Astronomy.
Here's how I connect to the COM port:-
SQM_h=COMM_OPEN(SQM_COM,$
BAUD = 9600 ,$
DATA = 8,$
MODE = 3, $
PARITY = 'N',$
STOP = 1)
and I get data out just fine...
Cheers,
Andrew
www.skippysky.com.au
I'm 18 months late here, but I run an SQM-LU, and read it it using my own little program written in Interactive Data Language (IDL), he language of professional Astronomy.
Here's how I connect to the COM port:-
SQM_h=COMM_OPEN(SQM_COM,$
BAUD = 9600 ,$
DATA = 8,$
MODE = 3, $
PARITY = 'N',$
STOP = 1)
and I get data out just fine...
Cheers,
Andrew
www.skippysky.com.au
-
- Posts: 275
- Joined: 10 Dec 2018, 16:23
Re: Read data from SQM-LU device
Andrew,
Thanks for the info. I would like to know more about this software.
Maybe you can email me.
John
Thanks for the info. I would like to know more about this software.
Maybe you can email me.
John