Beispiel #1
0
void BitButton10OnClick(tWidget *pWidget)
{

   //--- Close the existing handle ---
  if(hOpen>=0)
  {
     uart_Close(hOpen);
     hOpen = -1;
  }

  //--- Establish a new handle ---
  if(hOpen<0)
  {
     hOpen = uart_Open("COM1,9600,N,8,1");
  }

  //---  If success, display current COM Port settings on screen ---
  if(hOpen>=0)
  {
  LabelTextSet(&Label8, "COM1,9600,N,8,1");
  uart_SetTimeOut(hOpen, 300);
  }

  /*
  if(hOpen>=0)
      {
          BOOL ret;
          unsigned char *Buffer = {'AA'};//, '55', '04', '01', '03', '19', '20'};
          char* buf;
          ByteToChar(Buffer, buf, 1);

          ret = uart_Send(hOpen, buf);
      }
    */
}
Beispiel #2
0
void BitButton12OnClick(tWidget *pWidget)
{
      //--- Close the existing handle ---
  if(hOpen>=0)
  {
     uart_Close(hOpen);
     hOpen = -1;
  }

  //--- Establish a new handle ---
  if(hOpen<0)
  {
     hOpen = uart_Open("COM1,9600,N,8,1");
  }

  //---  If success, display current COM Port settings on screen ---
  if(hOpen>=0)
  {
  LabelTextSet(&Label8, "COM1,9600,N,8,1");
  uart_SetTimeOut(hOpen, 300);
  }


     if(hOpen>=0)
      {
          BOOL ret;

          char Buffer[1000];
          //char buf[]="AA 55 04 01 03 19 20";
          //char *test = strtok(buf, " ");
          unsigned char buf[]={0xAA, 0x55, 0x04, 0x01, 0x03, 0x19, 0x20};

          //int str_len = strlen(buf);
          char *ends=(char*)buf;
          ends[7]='\0';

          /*
          for(int i=0;i<str_len;i++)
          {
             if(buf[i]!=' ')
             {
                 Buffer[i] = strtol(buf[i], &ends, 16);
             }
          }
          Buffer[str_len]="";
         */
         //LabelTextSet(&Label8, (char*)10);
          //for(int nBytes=0;nBytes<str_len;nBytes++)
          //Buffer[nBytes] = strtol(test[nBytes], &ends, 16);
          //char* buf="p";
          //ByteToChar(Buffer, buf, 7);

          //char *s = "70", *ends;
          //char c = (char)strtol(s, &ends, 16);

          ret = uart_Send(hOpen, ends);
      }
}
Beispiel #3
0
void BitButton11OnClick(tWidget *pWidget)
{
  if(hOpen>=0)
  {
     uart_Close(hOpen);
     hOpen = -1;
     LabelTextSet(&Label8, "Press 'Start' to Begin");
     LabelTextSet(&Label4, "");
     LabelTextSet(&Label9, "");
  }
}
Beispiel #4
0
DMPAPI(COMPort *) com_Init(int com)
{
	COMPort *port;

	if ((port = (COMPort *)CreateCOMPort(com)) == NULL) return NULL;

	switch (com)
	{
		case COM1: case COM2: case COM3: case COM4: case COM5:
		case COM6: case COM7: case COM8: case COM9: case COM10:
		{
			if ((port->func = (void *)CreateUART(com)) == NULL) goto FAIL;
			if (uart_Init(port->func) == false)
			{
				uart_Close(port->func);
				goto FAIL;
			}
			
			port->Close              = uart_Close;
			port->SetTimeOut         = uart_SetTimeOut;
			port->Read               = uart_Read;
			port->Receive            = uart_Receive;
			port->QueryRxQueue       = uart_QueryRxQueue;
			port->RxQueueFull        = uart_RxQueueFull;
			port->RxQueueEmpty       = uart_RxQueueEmpty;
			port->FlushRxQueue       = uart_FlushRxQueue;
			port->Write              = uart_Write;
			port->Send               = uart_Send;
			port->QueryTxQueue       = uart_QueryTxQueue;
			port->TxQueueFull        = uart_TxQueueFull;
			port->TxQueueEmpty       = uart_TxQueueEmpty;
			port->FlushTxQueue       = uart_FlushTxQueue;
			port->TxReady            = uart_TxReady;
			port->FlushWFIFO         = uart_FlushWFIFO;
			port->SetBPS             = uart_SetBaud;
			port->SetFormat          = uart_SetFormat;
			port->SetFlowControl     = uart_SetFlowControl;
			port->EnableFIFO         = uart_SetHWFIFO;
			port->SetWFIFOSize       = uart_SetWFIFOSize;
			port->ClearRFIFO         = uart_ClearRFIFO;
			port->ClearWFIFO         = uart_ClearWFIFO;
			port->SetLSRHandler      = uart_SetLSRHandler;
			port->SetMSRHandler      = uart_SetMSRHandler;
			port->GetLSR             = uart_GetLSR;
			port->GetMSR             = uart_GetMSR;
			port->EnableHalfDuplex   = uart_EnableHalfDuplex;
			port->EnableFullDuplex   = uart_EnableFullDuplex;
			port->EnableDebugMode    = uart_EnableDebugMode;
			port->DisableDebugMode   = uart_DisableDebugMode;
			
			return port;
		}
		
		case USB_COM:
		{
			if ((port->func = (void *)CreateUSBDevice()) == NULL) goto FAIL;
			if (set_usb_pins == false)
			{
				err_print((char*)"%s: no set USB-Device pins.\n", __FUNCTION__);
				usb_Close(port->func);
				goto FAIL;
			}
			if (usb_SetUSBPins(port->func, usb_detect_port, usb_detect_pin, usb_on_off_port, usb_on_off_pin) == false)
			{
				usb_Close(port->func);
				goto FAIL;
			}
			if (usb_Init(port->func) == false)
			{
				usb_Close(port->func);
				goto FAIL;
			}
			
			port->Close              = usb_Close;
			port->SetTimeOut         = usb_SetTimeOut;
			port->Read               = usb_Read;
			port->Receive            = usb_Receive;
			port->QueryRxQueue       = usb_QueryRxQueue;
			port->RxQueueFull        = usb_RxQueueFull;
			port->RxQueueEmpty       = usb_RxQueueEmpty;
			port->FlushRxQueue       = usb_FlushRxQueue;
			port->Write              = usb_Write;
			port->Send               = usb_Send;
			port->QueryTxQueue       = usb_QueryTxQueue;
			port->TxQueueFull        = usb_TxQueueFull;
			port->TxQueueEmpty       = usb_TxQueueEmpty;
			port->FlushTxQueue       = usb_FlushTxQueue;
			port->TxReady            = usb_TxReady;
			port->FlushWFIFO         = usb_FlushWFIFO;
			port->Ready              = usb_Ready;
			port->GetLineCoding      = usb_GetLineCoding;
			port->SetSerialState     = usb_SetSerialState;
			port->GetControlLineState= usb_GetControlLineState;
			
			return port;
		}
		
		case CAN_BUS:
		{
			if ((port->func = (void *)CreateCANBus(IO_PORT)) == NULL) goto FAIL;
			if (can_Init(port->func) == false)
			{
				can_Close(port->func);
				goto FAIL;
			}
			
			port->Close              = can_Close;
			port->SetTimeOut         = can_SetTimeOut;
			port->QueryRxQueue       = can_QueryRxQueue;
			port->RxQueueFull        = can_RxQueueFull;
			port->RxQueueEmpty       = can_RxQueueEmpty;
			port->FlushRxQueue       = can_FlushRxQueue;
			port->QueryTxQueue       = can_QueryTxQueue;
			port->TxQueueFull        = can_TxQueueFull;
			port->TxQueueEmpty       = can_TxQueueEmpty;
			port->FlushTxQueue       = can_FlushTxQueue;
			port->TxReady            = can_TxReady;
			port->FlushWFIFO         = can_FlushWFIFO;
			port->SetBPS             = can_SetBPS;
			port->Reset              = can_Reset;
			port->AddIDFilter        = can_AddIDFilter;
			port->GetIDFilter        = can_GetIDFilter;
			port->DelIDFilter        = can_DelIDFilter;
			port->ClearIDList        = can_ClearIDList;
			port->EnableBypass       = can_EnableBypass;
			port->DisableBypass      = can_DisableBypass;
			port->SetEWLimit         = can_SetEWLimit;
			port->GetEWLimit         = can_GetEWLimit;
			port->GetTxErrorCount    = can_GetTxErrorCount;
			port->GetRxErrorCount    = can_GetRxErrorCount;
			port->GetNowState        = can_GetNowState;
			port->EnableStoreError   = can_EnableStoreError;
			port->DisableStoreError  = can_DisableStoreError;
			port->SetCANBusOffHandler= can_SetCANBusOffHandler;
			port->PopError           = can_PopError;
			port->GetLastError       = can_GetLastError;
			port->ReadCAN            = can_Read;
			port->WriteCAN           = can_Write;
			
			return port;
		}
		
		default: break;
	};
	
FAIL:
	ker_Mfree(port);
	return NULL;
}