C # TCP Charging pile parameter setting tool writing summary

Source: Internet
Author: User

1. Wait for the client to connect, catch{} do not write exception processing, or error;
2. Manipulate other controls in the thread to use the delegate or cause a conflict; (or new thread)

The client on the connection is displayed in the list, and the        delegate void Setlistboxcallback (String str) is handled across the thread delegate;        public void Setlistbox (String str)        {            if (listboxclient.invokerequired)            {                Setlistboxcallback Setlistcallback = new Setlistboxcallback (setlistbox);                Listboxclient.invoke (Setlistcallback, str);            }            else            {                listBoxClient.Items.Add (str);            }        }


3. For help, use the HelpProvider of the platform (not resolved), you can use the KeyDown () event.

   if (E.KEYCODE==KEYS.F1)            {           System.Diagnostics.Process.Start ("Iexplore.exe", strpath);            }


4.CRC16 Check, Modbus low in front, high in the rear

Public byte[] Crc16_c (byte[] data)
{
BYTE Crc16lo;
BYTE Crc16hi; CRC Register
BYTE CL;       BYTE CH; Polynomial code &ha001
BYTE Savehi; BYTE Savelo;
Byte[] Tmpdata;
int I;
int Flag;
Crc16lo = 0xFF;
Crc16hi = 0xFF;
CL = 0x01;
CH = 0xA0;
Tmpdata = data;
for (int i = 0; i < tmpdata.length; i++)
{
Crc16lo = (byte) (crc16lo ^ tmpdata[i]); Each data is different from the CRC register or
for (Flag = 0; Flag <= 7; flag++)
{
Savehi = Crc16hi;
Savelo = Crc16lo;
Crc16hi = (byte) (Crc16hi >> 1); High-right Shift one
Crc16lo = (byte) (Crc16lo >> 1); Low right Shift one
if ((Savehi & 0x01) = = 0x01)//If the last digit of the high byte is 1
{
Crc16lo = (byte) (Crc16lo | 0x80); The lower byte is shifted right and the front 1
}//otherwise auto-fill 0
if ((Savelo & 0x01) = = 0x01)//If the LSB is 1, then the polynomial code is XOR-
{
Crc16hi = (byte) (crc16hi ^ CH);
Crc16lo = (byte) (crc16lo ^ CL);
}
}
}
byte[] Returndata = new byte[2];
Returndata[0] = Crc16lo; CRC Low
RETURNDATA[1] = Crc16hi; CRC High
return returndata;
}


5.TCP send a message to the next machine, sent a hexadecimal byte array, you need to send the string into hexadecimal byte data.
6. Because of a multi-client connection, use a timer loop to scan for connection access.
7. Use regular validation when verifying whether it is a number or floating-point.

  string regexftext = @ "^ (-?\d+) (\.\d+)? $";
Regex regexfloat = new Regex (Regexftext, regexoptions.none);
Regexfloat. IsMatch (Straveprice.trim ();

C # TCP Charging pile parameter setting tool writing summary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.