saleae / SaleaeSocketApi

The Saleae software includes a socket based interface for scripting and automation applications.
73 stars 35 forks source link

SalaeSocketAPIExample - NAK for settting trigger, capture time and ViewState #7

Open codinkai opened 6 years ago

codinkai commented 6 years ago

Hi everybody,

in my setup: Windows 10 with Visual Studio Community, Salae Logic 8, Salae Logic 1.2.18. The commands for setting trigger, settting capture time and setting ViewState respond with NAK. This leads to socket api exceptions. In SocketAPI.cs in Line 91 "throw new SaleaeSocketApiException();".

These are the outputs from the console, when I comment out Line 91.

Wrote data: SET_TRIGGER, , POSPULSE, 1E-06, 0,005, LOW, HIGH Response: NAK

Wrote data: SET_CAPTURE_SECONDS, 0,25 Response: NAK

Wrote data: SET_VIEWSTATE, 500,00, 0,00 Response: NAK

What could be the problem here? Thanks in advance

Marcus10110 commented 6 years ago

Sorry for the trouble! Looks like a bug in the Logic software and in the C# socket library - it doesn't handle your locale properly. You have comma characters where our application expects periods. A quick workaround might be to add this to the top of the static void Main( string[] args ) function:

var usCulture = new System.Globalization.CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = usCulture;
Thread.CurrentThread.CurrentUICulture = usCulture;

I think that should do it for now.

This might be a better solution:

System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
customCulture.NumberFormat.NumberDecimalSeparator = ".";

System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;

I need to look into best practices for handling this kind of problem with public APIs.

Let me know if you still have trouble with it.

s20550 commented 6 years ago

Thanks! This working solution!

But may not be necessary to force everyone to change culture:

--- a/SaleaeSocketApi/SocketApi.cs +++ b/SaleaeSocketApi/SocketApi.cs @@ -131,9 +131,9 @@ namespace Saleae.SocketApi command.Add( channel.GetDescription() ); if( channel == Trigger.PositivePulse || channel == Trigger.NegativePulse ) {