I have tried writing this question on Keysights community page, but apparently they have a lack of community. I am hoping there will be individuals here that can help me, however.
Anyways, I have written a program that talks to an Agilent 34970A roughly every minute (variable depending on input values, and also random depending on input values) and scans through almost 20 channels. I then parse all the data and make sure everything looks right. I have run into several issues, and I have worked through most of them, however, I am now stuck with one.
SOMETIMES, I get an exception when I first try to connect to the instrument. The short version of the exception is:
Keysight.CommandExpert.InstrumentAbstraction.CommunicationTimeoutException was unhandled
HResult=-2146233088
Message=Timed out while trying to query instrument errors
Source=Keysight.CommandExpert.Scpi
Timeout=10000
I have written my code in C#, and like I said it happen right when I try to connect to the instrument. This line of code is:
Ag3497x v34970A = new Ag3497x("ASRL1::INSTR");
How do I handle this exception? Originally I was using IVI-COM drivers, but found them to be cumbersome and unreliable. I read on here somewhere one person who preferred the SCPI commands, so I switched to these. However, when I was using the IVI drivers, there was a command to close the connection. I couldn't find on with the SCPI commands. Could this be part of the issue?
The full code I use to talk with and read data from the 34970A is as follows:
string readings = null;
Ag3497x v34970A = new Ag3497x("ASRL1::INSTR");
v34970A.SCPI.RST.Command();
v34970A.SCPI.DISPlay.TEXT.Command("CYCLE TESTER");
v34970A.Transport.DefaultTimeout.Set(-1);
v34970A.SCPI.CONFigure.VOLTage.AC.Command(100, "MAX", "#101:116");
v34970A.SCPI.SENSe.VOLTage.AC.BANDwidth.Command(1000, "#101:117");
v34970A.SCPI.CONFigure.VOLTage.AC.Command(10, "MAX", "#117");
v34970A.SCPI.SENSe.VOLTage.AC.BANDwidth.Command(1000, "#117");
v34970A.SCPI.CONFigure.VOLTage.AC.Command(300, "MAX", "#119");
v34970A.SCPI.SENSe.VOLTage.AC.BANDwidth.Command(60, "#119");
v34970A.SCPI.CONFigure.TEMPerature.Command("TCouple", "K", 1, "MAX", "#118");
v34970A.SCPI.ROUTe.SCAN.Command("#101:119");
v34970A.SCPI.TRIGger.COUNt.Command(1);
v34970A.SCPI.READ.QueryAllData(null, out readings);
I run this code up to 10,000 times as required by the test the program is written for. I am connective via SERIAL as you can see in the code.
Anyways, any help would be much appreciated. As am sure you could understand, when a program fails at cycle 8000 out of 10000, it can be very frustrated, especially when 10000 cycles can take more than 10 days to complete. Really, maybe I'll get lucky and someone will know how I can prevent this, but I'm truly looking for a way to handle this exception when it does happen, assuming it can't be prevented. So really, this long post is asking how to handle an exception. I have searched, but this answer has alluded me. If you would like to know any other detail, please let me know, and I will provide it promptly.
Thanks again,
Josh
Few suggestions:
Why do you have to call the Ag3497x constructor on each iteration? construct the device only once and reuse it.
What are the baud rate? cable length? consider shorter cables and smaller baud rate.
Consider sniffing out what exactly happening in the port while this exception is happening using some serial port sniffer like this one.
If everything else is fine and it seems like some issue within the Visa driver, if you don't have some response from Keysights, consider using a different visa driver or implement your own using SerialPort.
Related
I am writing a UWP app using the Windows.Devices.WiFi to basically get a lists of networks. Everything was working fine when I retrieved the information a time or two. However, I wanted to put the code into a timer so I can report regularly. Once I did this, I got "an attempt was made to establish a session to a network server, but there are already too many sessions established to that server."
I am not sure what is establishing connections as I am just trying to read the information. I am not even calling the ConnectAsync calls.
Can anyone help me out? I need to know what to dispose, or close, etc.
Update: Further analysis, I am finding that the call to FindAllAdaptersAsync multiple times is causing this issue.
I decided to cache up the list of adapters by only calling FindAllAdaptersAsync once. Thanks for the idea Henk. This seemed to fix my issue for now. However, I think that it is a bug with FindAllAdaptersAsync. I would think you should be able to call this as much as you like, unless maintaining the network connection is necessary every time. Or at least a way to free them up.
I was looking for some advice on the best approach to a TCP/IP based server. I have done quite a bit of looking on here and other sites and cant help think what I have saw is overkill for the purpose I need it for.
I have previously written one on a thread per connection basis which I now know wont scale well, but what I was thinking was rather that creating a new thread per connection I could use a ThreadPool and queue the incoming connections for processing as time isn't a massive issue (provided they will be processed in less that a minute or two of coming in).
The server itself will be used essentially for obtaining data from devices and will only occasionally have to send a response to the sending device to update settings (Again not really time critical as the devices are setup to stay connected for as long as they can and if for some reason if it becomes disconnected the response will be able to wait until the next time it sends a message).
What I wanted to know is will this scale better than the thread per connection scenario (I assume that it will due to the thread reuse) and roughly what kind of number of devices could this kind of setup support.
Also if this isn't deemed suitable could someone possibly provide a link or explanation of the SocketAsyncEventArgs method. I have done quite a bit of reading on the topic and seen examples but cant quite get my head around the order of events etc and why certain methods are called at the time the are.
Thanks for any and all help.
I have read the comments but could anybody elaborate on these?
Though to be honest i would prefer the initial approach of of rolling my own.
I am trying to evaluate ZeroMQ for a larger monitoring and data gathering system. On a smaller scale everything works nice but stepping up the load and scale a bit seems tricky.
Right now I am using a C# wrapper (clrzmq, 3.0.0-rc1) to create both a publisher and a subscriber application. I am binding the Publisher socket (1 socket, 1 context) to 1000 endpoints (localhost + a range of ports) and let the Subscriber applications socket (again 1 socket, 1 context) bind to the publisher endpoints.
This sometimes works, and sometimes not (I guess it relates to the max number of sockets handled by the process somehow). It seems to depend on in which order I start the applications but I cannot tell for sure. The only thing I see is nasty SEHExceptions, containing no details at all. If I create simple console applications I sometimes see low level C++ Asserts like:
Assertion failed: fds.size () <= FD_SETSIZE (......\src\select.cpp:70)
Assertion failed: Permission denied (......\src\signaler.cpp:281)
Assertion failed: Connection reset by peer (......\src\signaler.cpp:124)
Not very helpful to me. In the C# wrapper, the Context creation fails. It does not even get a chance to begin connecting to or even creating sockets. I would expect low level ZeroMQ errors to be handled by throwing exceptions, maybe I just have not understood how to deal with errors yet.
The questions I have right now is:
How do I create a (somewhat) realistic test setup to simulate 1000 separate publishers on a single machine (in real world 1 publisher = 1 machine) and a couple of Subscribers on Another machine, all using C#. Is that even possible?
More importantly, how do I trap ZeroMQ errors in C# code to be able to understand what goes wrong?
Since ZeroMQ seems pretty stable and mature I have a hard time believing 1000 publishers should be a problem to handle. However, I need better error support than currently available (unless I completely missed something here) in order to use ZeroMQ over C#.
Update:
After diggin into the source, I end up with a zmq_assert(...) leading to RaiseException (0x40000015, EXCEPTION_NONCONTINUABLE, 1, extra_info);. This will abruptly terminate the application after dumping the original assert statement to the console. This seems a bit harsh, but may well be the best option given that it is really unrecoverable. However, a somewhat better error message would not hurt. Not everyone knows what fds.size () <= FD_SETSIZE means. The comment in the source gives some clues, would be nice to have that comment in the error message. Anyway, given that my application is not a console app, this just leaves me with an unhandled SEHException, which does not seem to contain even the assert statement or line/file info. I wonder how many other bugs I will create that will result in other similar cryptical errors.
After looking into this a bit more, it seems the default number of sockets are set to 1024. The C# wrapper has a property on the Context object that should be able to change this setting but it is not working, at least not as expected. Also, the native zmqlib does not have this setting on the context object.
Running a setup like in the description does not seem possible, at least not using the clrzmq C# ZeroMQ wrapper. I solved it by running 500 publishers on a separate machine and another 500 plus 1000 subscribers on another machine. This worked nice without any errors.
The other topic is also a bit disappointing. When the maximum number of sockets are reached, ZeroMQ simply throws an uncatchable exception causing the application to crash abruptly. This is a fail fast approach, avoiding any further data/state corruption but unfortunatly also leaves very few clues to what happend that caused the application to die. Judging from other posts, it seems very hard to gather data for post-mortem when this happens. Catching the exception in the C# code seems impossible or very hard, and hooking into the stdout to capture the printed assert also seems very hard to achieve (if we are not running from a command prompt, in which case the assert message is printed just before the application dies).
All-in-all, this makes low-level trouble shooting and post-mortem analysis in a non-console C# setting very hard when ZeroMQ terminates via the zmq_assert(...) call. Hopefully this was an extreme case. Not all failure modes seems to cause termination in this abrupt way.
The default FD_SETSIZE is 1024 (defined in the MSVC libzmq project), so you will hit this about half-way through your test case. The other asserts tumble on from that.
Increase this in your libzmq project, to 4K or 8K, and things should work better.
As for the assert() call, it's too brutal on Windows, for sure. On Linux this gives a decent stack dump and enough information to trace the problem. Feel free to improve the assert macro so that it does something smarter, e.g. launch the debugger. In any case if you hit an assert you can't reasonably continue.
Asserting when the FD set is full, well, that could be handled better. If you know anything about C/C++, feel free to take a look at the code. We do depend on peoples' patches.
Also, if you feel 1024 is too small, feel free to raise this in the project and send us the patch.
A quick and dirty look into this problem suggest that you're creating too many socket connections for your computer. Check out this link on the max number of sockets from MSDN. The error's you are getting look suspiciously relevant enough for this to be a possible source of your error.
To be honest, having 1000 separate publishers seems like you are tackling the problem a little incorrectly for using zmq. Why not have 1 publisher and use 'namespaces' and have the subscribers SUBSCRIBE to what it needs to split out what messages subscribers get.
I'm coding in Java, on Android platform, but this isn't really a question for a specific programming language.
So ... If an error occurs in my program, i catch it within a try-catch statement and i would like to create an error number which I'll display to the user, giving him the opportunity to send me this error number.
The catch is that i would like to code the error in such a way that i get a small number (let's say a maximum of 5 digits) which i later on can decode and can find out exactly in which class, in which method and at which line number the error occured.
I'm guessing this is more of a cryptography issue, so has anyone got any ideas on how i should go about doing this?
EDIT
I was thinking of giving a number to each file, each method and somehow use these values to create the error number, but i'm not sure how to calculate the actual error number so that it will work the other way around (decode it correctly).
I will say it, this is a dreadful approach to debugging issues. What you want to do is set up an enumeration that dictates the error codes + descriptions. This would be similar to how Microsoft does it
ERROR_SUCCESS
0 (0x0)
The operation completed successfully
So on and so forth. That way you can publish these things to your users, so you reduce the amount of emails / complaints that you get (to some degree). Obfuscating the stack trace is going to be a nightmare for you, because it would almost seem that you are locking yourself into an unmanageable reporting system. As your code base grows and/or you add more custom exceptions you will quickly break your design. Also, this is a strong case of security through obscurity, wherein someone will potentially reverse engineer your process and start writing malicious code against you.
Better approach:
Get a JIRA account where the more technically savvy users can post the error plus description. I believe FogBugz also has this functionality where you can upload these types of things and it allows the users to crop the images to focus on what you are looking for specifically.
I've worked on a program that uses databases to send small messages from one PC to another. What I've done is put the database in a shared folder, have the program on the other PC connect to it (via a Path, no less), and there it is, a simple and easy way to get messages to and fro PCs on a network. Not the best option, but it's just homework, and the quick and dirty approach got me a grade.
But now the homework is done, and I'd like to improve upon what I did. The problem with the program is in the deployment stage. There are too many folders / installation paths and administrative / sharing issues regarding pathing directly to a database on a shared folder.
So the good folks here in stackoverflow advised me to try Socket Programming, which I think is a bit out of my league. But you never know...
Also, I'm aware of the difference between Sync and Async socket programming. One blocks, the other doesn't. The program I'm working on is a simple turn-based game, so I thought Synchronous might be good enough, since if it's not your turn, you really can't do anything. The issue however is that the program is treated as "not responding". I tried asynchronous, but ran into problems with threading, something I consider WAY out of my league.
Logically, the program is simple. One host, one client. Upon client connection, host sends data. Then client receives, send out its own data. And so on, until one player loses.
I'm sorry to say only .NET 2.0 is installed in my school. No WCF or anything. Also, it must be done in C# Windows Forms, so XNA is out.
So, I'd like to ask... is there an easy way to get into Socket Programming? Any guides / sample projects that can help? Pre-made codes that can be studied, and adapted?
Majority of the samples I found and adapted are chat applications, which I thought good enough, but making it modular simply breaks it.
The chat application examples you encountered should be enough. It is not clear to me what you refer to as "making it modular".
What you need is to design a protocol to be sent over the connection, an agreement of rules so to say, so that one knows what the other is talking about. So instead of sending plain text (chat) you can send the following:
0x03 (length of the message)
0x0A (move command in this fictional protocol)
0x02 (parameter 1 of the command, X coordinate in this case, it's all defined in the protocol design)
0x05 (parameter 2 of the command, Y coordinate in this case, it's all defined in the protocol design)
Now it's entirely up to you what happens after you received and interpreted the data. Personally I would go for the Async solution, since it leaves your program to do other stuff (graphics?). And it's more easily adaptable in code, in my experience.
I've made some classes which can be used to transport objects over a socket using the BinaryFormatter.
Here are some tests for my BinaryTransport class:
http://fadd.codeplex.com/SourceControl/changeset/view/67972#1055425
The actual class:
http://fadd.codeplex.com/SourceControl/changeset/view/67972#1054822
Do note that it's a while ago that I wrote them. I just noticed some small bugs. But either use them or just study the classes to learn more.
I remember when I started with socket communication in C# I tried to implement a simple chat program between a client and a server and then between multiple clients. Here is the tutorial that I was reading then: http://www.codeproject.com/KB/IP/TCPIPChat.aspx
If you want the full code I can upload my final project and you can study the code. It also uses multithreading so you can see how to handle this situation in GUI applications.
Side note: Wow, that database idea is the craziest thing I've seen in terms of PC-to-PC communication. Well done!
One interesting, useful and easy exercise you can do to learn about sockets (which C# makes it easier even) was creating a TCP-based logger.
During development every programmer needs a way to know what's happening under the hood at certain points. Without a logger you would normally write something like:
Console.WriteLine( "blah" );
which results in a dull, unfiltered, unorganized string thrown to the output window.
I created a TCP-based logger very easily using sockets. In one hand you have a separate Winforms application (the server), which is in charge of listening to incoming messages and beautifully displaying them on a rich-content control. In the other hand, you write a very simple class (the client) with a single function like:
public static class MyConsole
{
public static void WriteLine( string message, string whatever )
{
// send to the net
if( mTcpSocket.Connected )
mTcpSocket.Send( message );
// in case the server is not there we still have regular output
Console.WriteLine( message );
}
}
I created this logger once and have been using it ever since. Furthermore, given its tcp nature, with minor changes on the server side I've been successfully using it from different languages, as C# and Java, and now using it from ActionScript.