예제 #1
0
 /// <summary>
 /// The GetCommState function retrieves the current control settings for a specified communications device.
 /// </summary>
 /// <param name="BaudRate">Baud rate at which the communications device operates.</param>
 /// <param name="Parity">If param is TRUE, parity checking is performed and errors are reported.</param>
 /// <param name="StopBits">Number of stop bits to be used.
 /// </param>
 /// <param name="ByteSize">Number of bits in the bytes transmitted and received.</param>
 /// <returns></returns>
 protected bool GetComStatSel
     (ref Int32 BaudRate, ref RSWrapper.ParityBit Parity, ref RSWrapper.StopBits StopBits, ref byte ByteSize)
 {
     RSWrapper.DCB PortDCB = new RSWrapper.DCB();
     if (!RSWrapper.GetCommState(hPort, ref PortDCB))
     {
         return(false);
     }
     BaudRate = PortDCB.BaudRate;
     ByteSize = PortDCB.ByteSize;
     Parity   = PortDCB.Parity;
     StopBits = PortDCB.stopBits;
     return(true);
 }
예제 #2
0
 /// <summary>
 /// This function configures a communications device
 /// </summary>
 /// <param name="BaudRate">Specifies the baud rate at which the communication device operates.</param>
 /// <param name="Parity">Specifies the parity scheme to be used.</param>
 /// <param name="StopBits">Specifies the number of stop bits to be used.</param>
 /// <param name="ByteSize">Specifies the number of bits in the bytes transmitted and received.</param>
 /// <returns>true indicates success.</returns>
 protected bool SetComStat
     (RSWrapper.BAUD_RATE BaudRate, RSWrapper.ParityBit Parity, RSWrapper.StopBits StopBits, byte ByteSize)
 {
     RSWrapper.DCB PortDCB = new RSWrapper.DCB();
     if (!RSWrapper.GetCommState(hPort, ref PortDCB))
     {
         return(false);
     }
     PortDCB.BaudRate = (int)BaudRate;
     PortDCB.ByteSize = ByteSize;
     PortDCB.Parity   = Parity;
     PortDCB.stopBits = StopBits;
     if (!RSWrapper.SetCommState(hPort, ref PortDCB))
     {
         return(false);
     }
     return(true);
 }