[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: C#/NLua + string.pack - Binary Message Not What I Expect
- From: Sean Conner <sean@...>
- Date: Thu, 17 Oct 2019 16:40:53 -0400
It was thus said that the Great Russell Haley once stated:
> Hi,
>
> My project is a serial port console written in C# that uses an embedded Lua
> interpreter via NLua. I have a lua script to send a binary messages out the
> serial port. I am using string.pack to create the message. My lua script:
>
> local bytes = {0x5AA5}
[ snip ]
> My C# WriteRemote is simple:
> public void WriteRemote(string data, bool appendLineEnding = true)
> {
> if(_logging)
> {
> _scriptLog.WriteLine(data);
> }
> data = appendLineEnding ? data + _lineEnding : data;
> byte[] bytes = Encoding.UTF8.GetBytes(data);
^^^^
The string you are generating, 0xA5,0x5A, is not a valid UTF-8 string.
Could that perhaps be the issue?
-spc