So I’m working on porting some legacy .NETMF code to TinyCLR. We are upgrading our board from a GHI G120 to a SCM20260D SoM.
I am using a Teltonika RUT240 LTE Modem/Router connected to our board via ethernet. I know it’s not an issue, since our old G120 NETMF board works with the same router configuration (I am able to hot-swap the same router to the old/new board and the old one is able to connect to the server)
Firstly, here’s my Ethernet init code (nearly copy paste from doc examples):
var gpioController = GpioController.GetDefault();
var resetPin = gpioController.OpenPin(SC20260.GpioPin.PG3);
resetPin.SetDriveMode(GpioPinDriveMode.Output);
resetPin.Write(GpioPinValue.Low);
Thread.Sleep(100);
resetPin.Write(GpioPinValue.High);
Thread.Sleep(100);
_nw = NetworkController.FromName(SC20260.NetworkController.EthernetEmac);
var nif = new EthernetNetworkInterfaceSettings();
var ncis = new BuiltInNetworkCommunicationInterfaceSettings();
nif.Address = new IPAddress(new byte[] { 192, 168, 1, 200 });
nif.SubnetMask = new IPAddress(new byte[] { 255, 255, 255, 0 });
// Teltonika Router LAN IP
nif.GatewayAddress = new IPAddress(new byte[] { 192, 168, 1, 1 });
nif.DnsAddresses = new IPAddress[]
{new IPAddress(new byte[] { 192,168,1,1 })};
nif.MacAddress = new byte[] { 0xE8, 0x7F, 0xA2, 0xD1, 0x36, 0xD5 };
nif.DhcpEnable = false;
nif.DynamicDnsEnable = false;
_nw.SetInterfaceSettings(nif);
_nw.SetCommunicationInterfaceSettings(ncis);
_nw.SetAsDefaultController();
_nw.NetworkAddressChanged += NetworkController_NetworkAddressChanged;
_nw.NetworkLinkConnectedChanged += NetworkController_NetworkLinkConnectedChanged;
_nw.Enable();
And here’s my basic Socket connect/send/receive code:
Socket soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
soc.ReceiveTimeout = 30000;
soc.SendTimeout = 30000;
IPEndPoint ep = new IPEndPoint("SERVER_IP", 20000);
soc.Connect(ep);
soc.Send(buf);
soc.Receive(respBuf);
Now, the above socket code is identical between the NETMF and TinyCLR versions of firmware I’m working on.
I have an app running on our server that accepts socket connections and receives/responds to data on the above specified port (has been working for years with old NETMF boards).
(note: I can only embed 1 image here so the formatting is a little weird, so the images are denoted in order)
Here’s a wireshark capture of the old NETMF succesfully transacting with the server(1):
(PINK = Device IP, RED = Server IP)
Now this all works, but when trying to use TinyCLR, i get a SocketException on the Connect method call (with no additional information), and here’s that capture (2):
Furthermore, i noticed when i crank the socket send/receive timeouts to 30_000_000, the connect no longer throws an exception, but i get errors while sending/receiving data(3):
I have verified that the packets sent from the NETMF and TinyCLR devices are identical (at least from looking at the byte array passed to the Send() method)
Any ideas here? I can’t find any differences between the logic in either system, and I’m scratching my head. I have tried to set the clock speed lower on the SCM20260D as mentioned in other forum posts, but with no luck.