1
0
mirror of https://github.com/sjlongland/adv950.git synced 2025-09-13 10:43:14 +10:00
adv950/getconfig/getconfig.c
Stuart Longland 98f879a253
Initial check-in, Advantech ADV950 serial driver v3.33.
This is a check-in of the Advantech ADV950 serial driver, used with the
UNO-1150 series of industrial computers, as sourced from:

http://support.advantech.com/support/DownloadSRDetail_New.aspx?SR_ID=1-GLBRCD&Doc_Source=Download

This builds with kernel 3.0.1, but does not build with contemporary
kernels (i.e. ones that are still in support).

I suspect this is a hacked up version of Russel King's 8250 serial
driver from 2001.  First step, let's get it building against the current
kernel (v4.10.1) and then we'll look at integrating this into 8250
proper.
2017-03-05 10:29:50 +10:00

90 lines
2.4 KiB
C

//******************************************************************************
//
// Copyright (c) 2008 Advantech Industrial Automation Group.
//
// Oxford PCI-954/952/16C950 with Advantech RS232/422/485 capacities
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the Free Software Foundation, Inc., 59
// Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
//
//
//******************************************************************************
//***********************************************************************
// File: getconfig.c
// Version: 1.01.1
// Author: Po-Cheng Chen
// Purpose: Get serial port configuration, such as RS232 or RS422/485
//***********************************************************************
//***********************************************************************
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <asm/ioctls.h>
#include <linux/serial.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int i, ttynum, fd;
char ttyname[80];
struct serial_struct serinfo;
if(argc < 3)
{
printf("Usage:\n");
printf("%s TTYNAME TTYNUM", argv[0]);
return 1;
}
ttynum = atoi(argv[2]);
for(i=0;i<ttynum;i++)
{
sprintf(ttyname, "/dev/%s%d", argv[1], i);
if((fd = open(ttyname, O_RDWR | O_NDELAY)) == -1)
break;
// test serial port exist or not
if(write(fd, ttyname, strlen(ttyname)) == -1)
break;
// get serial port information
serinfo.reserved_char[0] = 0;
if (ioctl(fd, TIOCGSERIAL, &serinfo) < 0)
{
printf("Cannot get serial info\n");
close(fd);
return 2;
}
// get serial port type configuration
if (serinfo.reserved_char[0] == 0)
{
// RS232
printf("%s is RS232\n", ttyname);
}
else
{
// RS422/485
printf("%s is RS422/485\n", ttyname);
}
close(fd);
}
return 0;
}