cancel
Showing results for 
Search instead for 
Did you mean: 

CLI Example for Sensor Box Pro

Smithson
Associate III

The sensor box pro is a neat device.  If I use the CLI Example program and the USB cable, I can get 8000 data points per second, if I use a traditional C# program I get 8 data points per second.  

The CLI yields dat files, which can be read with a simple C# program, although why you would mix 6 and 4 data groups is beyond my skill set to understand, but it is easier to use than Python and MEMS Set.   And it is easier to do the byte data in C#.  (It took less time to write this program than I spent trying to get Python to work.)

CLI Example makes me type enter to start.  I have many ST.COM accelerometers all over the world and I am not going to type enter to start, but the main.cpp and main.h and the cmake lists file will not compile in CMAKE or Visual Studio.  So I cannot fix the challenging feature. 

Could we get VS SLNX file and the C++ code for this program as part of the SLNX so it is easy to take out the enter statement and break the output up into data sets that can be analyzed in near real time, like 8 seconds on a bridge in a snow storm in the middle of the night, whilst I am sound asleep 1000 miles away.  

 

This will read your dat files. there is some junk in there as it took me a while to work out the byte structure as the documentation shows a nice picture, but it is without numbers.  

 

I need to improve the routine to break up the bytes, but that is ok as long as the accelerometer is flat. 

One looks for say 8 seconds of record, time for a truck to pass over the bridge, do a FFT preferably in Intel Fortran but who cares and the record the data. After a year you have 3 million records and we then have a good idea about the bridge.  

I would upload a picture to show some output, but it will not let me.  

Thanks.  

<< Cannot include code as message cannot exceed 30000 characters. >>  

The file type (.cs) is not supported. Valid file types are: ai, avi, mp4, bmp, csv, doc, cpd, docx, flv, gif, gz, tar.gz, har, ico, jpg, jpeg, log, mov, mpg, mpeg, mp3, odt, odp, ods, pdf, png, pps, ppt, pptx, rar, rm, tif, tiff, txt, xlr, xls, xlsx, xml, wmv, wav, z, 7z, ioc, hex, c, cc, cpp, h, hpp, tar, xz, dts, s, zip.

One is left to wonder.  Ah, I compress to zip.  

 

29 REPLIES 29

Dear Simone:

I am wise now on the insides of your json files, but the manual is rather light on all the details for the Sensor Box pro.  

John

Dear Simone:

Thank you for all your help.  I apologize for being slow at picking this new device up.  

John

Dear Simone:

The Intel Fortran expert who has offered suggestions as to how to make this work in Fortran had a number of comments.  See below.   I could not get it to work with your cmake file.  

--------------------------------------------------------------------------------------------------------------------------------------------------

The person who put together the build script (makefile) for Win32 obviously never tried it. You cannot link directly to a DLL - the linker wants an "export library", which is not provided in the ZIP. There are a few ways to handle this.

  1. Convert the DLL to a LIB - GitHub - generate94/convert_dll_to_lib · GitHub claims to do this.
  2. Use a .DEF file (the above tool generates one as a step - the LIB is easier to use
  3. Use the Windows API functions LoadLibrary and GetProcAddress to dynamically load the DLL and create procedure pointers. There is a DynamicLoad example in the old Windows Fortran samples ZIP (under the DLL subfolder).

I'd probably go with option 1.

Note also that you'll want to have any DLLs needed in your project folder (or in the folder containing the EXE), otherwise they will not be found.

You'll want to create a module with interfaces to the routines in the DLL(s) and use the .h files as a guide. It's good that the C++ code is unmanaged, as otherwise your task would be far more difficult.

--------------------------------------------------------------------------------------------------------------------------------------------------------

I will follow Option 1.  

 

Dear Simone:

I hate to say so, but this is not a solution.  

I now have your program somewhat running on Intel C++, but it is finding errors in the code that means that the code was not compiled with Intel C++ or Visual C++. I tried both.  Any idea which C++ compiler was used on Windows?

It would really help if I could get the C++ code for the datalog dll, there are two functions that are causing some pain. 

The problem functions are :

	AddFunc12 phs_datalog_start_log = (AddFunc12)GetProcAddress(hinstLib, "phs_datalog_start_log"); //(deviceID, 1, &pnpl_response);

 and the free memory function. The start log runs but returns garbage, and the free memory just fails.  

I did find that there is an undocumented feature so that if I use a -y on the command line, it bypasses your wait to press a key and now with the batch file I can loop for as long as I want.  You might amend the read.me as I cannot be the only person with this thought. 

The program I called Clip after the famous MS Clippy, it was late at night.  

I enclose the program as it now runs.  

John

 

No problem.  I have the C++ code running, but it is returning errors on two of the DLL functions on the data log software. As I do not have the C++ code, I cannot find out what is causing the errors.  

The C++ shows the impact of being developed over a long period, so there are many C++ flavours inside the app. I am running it on Intel C++ and using the C++ 20 language version, it would be nice to use the safer memory functions in the app from C++. 

The CLI-Example can be made to run permanently with a batch file and the use of the -Y input argument, which works nicely but it a bit buried in the documentation.  

If you want a bit more info, you can see some discussion on the Intel Fortran Forum, I want to get it running in Fortran as post processing is much easier.

John

 

I forgot, this will all lead to dual quaternions that will solve the bridge movement visualization problems. 

Dear Human Programmer:

The CLI-Example program for the Sensor Tile Box pro has a number of interesting features.  

1. You can use g++ or one can languish in some sort of programming hell trying to get Intel C++ to work.  

2. With the make file one can finally put just the right stuff in the main directory and get all the other stuff into an other directory where it can be ignored. 

3. One can add the make file to the run batch file and at least pretend we are not in 1988 and using VEDIT with its compiler mode.  Put in a three second delay so you can spot the errors. 

4. You can then just use MSVS to edit the main.cpp so at least it looks pretty.  Then there are only two buttons to press. 

5. On Windows I can only get the make to compile in 32 bit.  

6. When the program runs, one needs to know where the data is going and to the program main directory is not a long term viable solution.  It also helps if the program prints out where you store the data as one forgets sometimes, I was at the dentist this morning and the human asked me three times did I want mint flavour, one wonders at dementia.  But I remembered the three times. 

7. If you have a suspect bridge then the normal time to tell people it is suspect is about 8 seconds.  That means, you collect the data for 8 seconds, then run up a thread and do an FFT and checks in the next 8 seconds, and then telegraph the client something is wrong.  Clients like it when you get it right, they become annoyed otherwise. 

8. The MKI210 V2 will not restart even with a cold restart on the computer, one has to use a USBGEAR Hub to turn them on and off.   I know this is a fact as I have a couple in Washington and I am fixing them for the hub now.  

9. Using EXIT as a variable in a C++ program is a challenge, it is simple to make it a name that means something, like I_am_lost_find_me,  one can read about the dog in NZ.  

10 Leaving off STD:: is not recommended practice, so I read a few minutes ago. 

11. It is possible to make CLI_example loop nicely and save multiple data files with about 10 seconds of data each and also turn off all the clutter that comes in the beginning.    

12 The CHM file has a nice index, so does the OED. 

13.  It is possible to add a subroutine 

int sendError(std::string message) {
    
	logMessage(LOG_LEVEL_ERROR, message);
            std::cout << "Press any key to exit !!!!!!!!!!!!!!!!!!!!!!\n";
            getchar();
            return -1;
	
}

and remove about 100 lines of the same three lines that make the program interesting to read.  

14.  The interesting start to each error message hsdatalog etc.... is interesting.  

15. Automode is sketchy.  I know this, sometimes it works and sometimes it does not. 

16. Anyway, back to Byte program to analyze this new data set.  

17. I would have liked to have used using  the following, but it threw errors that were beyond my skill set. 

using nlohmann::json

18.  If you use 13 then you only need, 25 times 4 is 100 fewer lines and it is easier to read.  

int ret = sendError("Error occurred while retrieving device configuration");

 I19. It was suggested I should ask the formal help email people, they sent me to this forum which "has the real experts" I am paraphrasing a titch but not a tad. 

20.  Clip6 now is at a stage of some use.  

21. There are six million bridges in the world, a small subset, are monitored by ST.COM devices, not a lot. Most bridges had a design life of 60 to 100 years and many were built before 1970.  The ST.COM accelerometer very nicely (my 2nd Grade teacher said not to use very, but here I will), determines the rate of decay. Most bridges are inspected visually, by humans, I am a good human structural engineer, as I once said to Sister Elizabeth of the Dominican Order when asked if it was safe, my reply was probably but let us get in the survey team.  We demolished it the next day.   The ST.COM tells me exactly how fast it is degrading. 

22. 21 is essentially caring about people in old structures, I care, and so I ask these *** questions, because the Sensor Tile Box Pro is really good, ok aside from using G++, C++ and locked dll's.  I realize one works with what one has got, but sometimes when the building is collapsing and the Dominican Sisters are on their knees praying, which happened, one hopes that the equipment is good.  I had to apologize to Sister Mary for dropping 5 tonnes of concrete on her rose garden.  She did not mind, very nice Nun.  Sister Elizabeth said they stopped praying once, it cleared the building, it hit the rose garden next to the building.  

23. The code for the hsdata dll would be nice.  

 

I hope I have not bored anyone.  

John

 

 

I have not had this much computer fun since 1986 and AutoDESK added AutoLisp to AutoCAD.  I can remember learning Lisp for the AutoCad manual, a terse book of no examples.  

But there is Winston and Horne, if you have not read their book, you are missing one of the best computer programming books ever.  Although Sussman is still the king. 

Anyway, C++ is a challenge, but no where near Lisp.  

But LISP teaches you to use short functions.  And recursion and lambda. 

Anyway thanks to the people who invent this stuff, maintain this board and read and answer questions, the world would be a far worse place without you. 

Picture is IT telling you some software is not allowed or you are not within the security rules.

YKe2jZdaj2iB8CU3iQmP1UtuRI8XVv26iCmTIEHGAA4G-OdqrdkG5eADh9tzkPFgw4qDlLTDnQ=s900-c-k-c0x00ffffff-no-rj-2802897101.jpg

 

His name is Gronk. 

005700355130501620333154

This is the serial number for my Sensor Tile Box,  

Even if I drop off the two zeros, this is a number larger than a long, would cover more grains of sand than some engineer has estimated for the world.  

I will not ask for the reason for this number I am sure there are many, but is there a code to the number like

0057  country code

0035513 random number of parking spaces at st headquarters, which I have to assume is in Italy

5 a beautiful prime,  

162 the age of the ?????????????????????

333154  the real serial number, but we want it to be a bit longer. Which is why new cheque books always begin at 1000 for a new account.  

Thanks for the humour. 

PS:  I once needed a stack of ST accelerometers, and in the USA the supply was limited on number one could purchase, there were about 20 in the us at that time, I needed more, so I went to the UK and the guy said you can have as many as you like.  Got to love the British Shopkeeper. 

 

static readonly DateTime Epoch = new DateTime(1895, 6, 6, 17, 8, 51, DateTimeKind.Utc);

 That is about the date my paternal great grandparents were married, they died just before I was born.  

The 8 byte time stamp on the Sensor board give garbage if I use all 8 bytes and I am told by the kind engineer that is is in seconds, so using a note on the web, excellent source of facts and knowledge, at least on C#,  I used the least four bits and got from starting at 1900 the year 2030.  Subtracting to match I got a start date of epoch.  

Thank you for making the end of a day humourous.  I am aware that it is not ST.COM's intent, but you make a fair fist of it most days.   Re spell checker, the OED says humourous as the first entry.  

humourous.png