C# and Excel. Output Data Via Serial Port, with 2 Serial Ports

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 1752 Views - Last Post: 25 April 2016 - 06:42 AM Rate Topic: -----

#1 aqibi2000   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-April 16

C# and Excel. Output Data Via Serial Port, with 2 Serial Ports

Posted 25 April 2016 - 02:28 AM

Hello, I need assistance in creating a program which has 2 serial ports with 2 different functions.

1: Input Serial data 4 bits long from Serial port number 1 (RX) to Excel.

2: To then Output a string of data 16 bits long taken from Excel to a Serial port number 2 (TX)

I'm having difficult integrating with excel


I've tried:

   using System.IO.Ports;

    class SerialPortCustom
    {
        SerialPort SP = new SerialPort();      

        public SerialPortCustom()
        {
            SP.BaudRate = 57600;
            SP.Handshake = Handshake.None;
            SP.Parity = Parity.None;
            SP.PortName = " ";
            SP.StopBits = System.IO.Ports.StopBits.One;
            SP.DataBits = 8;
        }
  
public void SP_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {        
            stream_buffer[0] = SP.ReadByte();   //read 1st byte
        }


This post has been edited by Skydiver: 25 April 2016 - 06:07 AM
Reason for edit:: Put code in code tags. Learn to do this yourself.


Is This A Good Question/Topic? 0
  • +

Replies To: C# and Excel. Output Data Via Serial Port, with 2 Serial Ports

#2 Damage   User is offline

  • Lord of Schwing
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,989
  • Joined: 05-June 08

Re: C# and Excel. Output Data Via Serial Port, with 2 Serial Ports

Posted 25 April 2016 - 02:47 AM

Are you getting an error or whats the problem you're running into?
Was This Post Helpful? 0
  • +
  • -

#3 aqibi2000   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-April 16

Re: C# and Excel. Output Data Via Serial Port, with 2 Serial Ports

Posted 25 April 2016 - 02:50 AM

View PostDamage, on 25 April 2016 - 02:47 AM, said:

Are you getting an error or whats the problem you're running into?


I'm new to c# with c++ experience. I'm not sure how the c# will integrate into Excel. Stumped which direction to take. I'm okay with finding errors in code but actually this is more of an understanding the process type of problem I have.
Was This Post Helpful? 0
  • +
  • -

#4 horace   User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: C# and Excel. Output Data Via Serial Port, with 2 Serial Ports

Posted 25 April 2016 - 02:54 AM

what is the problem?
if I run this program it opens COM8 OK
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;

namespace serialport1
{
    class Program
    {
        static void Main(string[] args)
        {
            SerialPortCustom s = new SerialPortCustom();
        }
    }
}


class SerialPortCustom
{
    SerialPort SP = new SerialPort();
    int[] stream_buffer = new int[100];

    public SerialPortCustom()
    {
        SP.BaudRate = 57600;
        SP.Handshake = Handshake.None;
        SP.Parity = Parity.None;
        SP.PortName = "COM8";
        SP.StopBits = System.IO.Ports.StopBits.One;
        SP.DataBits = 8;
        SP.Open();
        Console.WriteLine("serial port open");
    }

    public void SP_DataReceived(object sender, SerialDataReceivedEventArgs e)
    {
        stream_buffer[0] = SP.ReadByte(); //read 1st byte
    }
}


Was This Post Helpful? 0
  • +
  • -

#5 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6328
  • View blog
  • Posts: 21,730
  • Joined: 05-May 12

Re: C# and Excel. Output Data Via Serial Port, with 2 Serial Ports

Posted 25 April 2016 - 03:59 AM

The first question I have is why is it essential that you use Excel? There are much more efficient and robust ways to buffer bits than using Excel.
Was This Post Helpful? 0
  • +
  • -

#6 aqibi2000   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-April 16

Re: C# and Excel. Output Data Via Serial Port, with 2 Serial Ports

Posted 25 April 2016 - 04:01 AM

View PostSkydiver, on 25 April 2016 - 03:59 AM, said:

The first question I have is why is it essential that you use Excel? There are much more efficient ways to buffer bits than Excel.



I have a specific algorithm and UI in excel which is unchangeable with a system I am using.
The results are processed and sorted via Macros in excel so are to be left alone since there are several hundreds of individual processes occurring.

Thanks
Was This Post Helpful? 0
  • +
  • -

#7 horace   User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: C# and Excel. Output Data Via Serial Port, with 2 Serial Ports

Posted 25 April 2016 - 04:04 AM

have you looked at
https://support.micr...en-us/kb/302084

This post has been edited by horace: 25 April 2016 - 04:06 AM

Was This Post Helpful? 0
  • +
  • -

#8 aqibi2000   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-April 16

Re: C# and Excel. Output Data Via Serial Port, with 2 Serial Ports

Posted 25 April 2016 - 04:20 AM

View Posthorace, on 25 April 2016 - 04:04 AM, said:




I will look into that now.


Here's an overall diagram of what I wish to achieve with your support.




Thanks everyone

View Postaqibi2000, on 25 April 2016 - 04:19 AM, said:

View Posthorace, on 25 April 2016 - 04:04 AM, said:




I will look into that now.


Here's an overall diagram of what I wish to achieve with your support.




Thanks everyone

Was This Post Helpful? 0
  • +
  • -

#9 horace   User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: C# and Excel. Output Data Via Serial Port, with 2 Serial Ports

Posted 25 April 2016 - 04:50 AM

View Postaqibi2000, on 25 April 2016 - 12:01 PM, said:

I have a specific algorithm and UI in excel which is unchangeable with a system I am using.
The results are processed and sorted via Macros in excel so are to be left alone since there are several hundreds of individual processes occurring.

how does you excel system get its information at present?
if it is from files it may be simpler for your serial port program to write its data to a file and then for excel to read and process it
Was This Post Helpful? 0
  • +
  • -

#10 aqibi2000   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-April 16

Re: C# and Excel. Output Data Via Serial Port, with 2 Serial Ports

Posted 25 April 2016 - 04:53 AM

View Posthorace, on 25 April 2016 - 04:50 AM, said:

View Postaqibi2000, on 25 April 2016 - 12:01 PM, said:

I have a specific algorithm and UI in excel which is unchangeable with a system I am using.
The results are processed and sorted via Macros in excel so are to be left alone since there are several hundreds of individual processes occurring.

how does you excel system get its information at present?
if it is from files it may be simpler for your serial port program to write its data to a file and then for excel to read and process it



Currently I was clicking on a macro, the after computing the value manually copying the string to a terminal (putty) and sending the values individually, however this is no longer viable.
Was This Post Helpful? 0
  • +
  • -

#11 horace   User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: C# and Excel. Output Data Via Serial Port, with 2 Serial Ports

Posted 25 April 2016 - 05:00 AM

so you want excel to transmit data to the serial port and receive replies for processing?

I done similar applications in C++ and Matlab but not excel but I don't see why it is not possible

This post has been edited by horace: 25 April 2016 - 05:09 AM

Was This Post Helpful? 0
  • +
  • -

#12 aqibi2000   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-April 16

Re: C# and Excel. Output Data Via Serial Port, with 2 Serial Ports

Posted 25 April 2016 - 05:20 AM

View Posthorace, on 25 April 2016 - 05:00 AM, said:

so you want excel to transmit data to the serial port and receive replies for processing?

I done similar applications in C++ and Matlab but not excel but I don't see why it is not possible



I tried twice to upload this image to help demonstrate but it just not happening.
There are 2 Serial ports in total


                              A                                                         B
______________________                 ___________________________________________             ______________________
| Serial Data Input  |                |                                           |            | Serial Data Output  |
| COM2               |--------------->|EXCEL Super Commutation Model              |----------->| COM 3               |
| Only Transmitting  |                | Data link A = input, Data link B = output |            | Only Receiving      |
|____________________|                |___________________________________________|            |_____________________|



This post has been edited by Skydiver: 25 April 2016 - 06:00 AM
Reason for edit:: Put diagram in code tags to preserve formatting.

Was This Post Helpful? 0
  • +
  • -

#13 horace   User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: C# and Excel. Output Data Via Serial Port, with 2 Serial Ports

Posted 25 April 2016 - 05:27 AM

if you use one COM port for transmit and one for receive is there any particular reason for two using seperate COM ports? e.g. different speeds? but I don't see any problem with two ports - I have had applications with two or three ports operating
Was This Post Helpful? 0
  • +
  • -

#14 aqibi2000   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 25-April 16

Re: C# and Excel. Output Data Via Serial Port, with 2 Serial Ports

Posted 25 April 2016 - 05:37 AM

Both COM ports are physically separate devices, running different baud rates, and stop/start bit parity levels.

One is a USB Bluetooth module, one is a USB to Serial converter. It's not physically connected to typical Desktop RS232 port.


I'm trying to keep this as streamlined as possible as I need to use this on small laptops with minimal RAM + HDD space, installing VB6 or Visual studio won't be possible. The MSCOMM32 method seems the least resource hungry, this is annoying.
Was This Post Helpful? 0
  • +
  • -

#15 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6328
  • View blog
  • Posts: 21,730
  • Joined: 05-May 12

Re: C# and Excel. Output Data Via Serial Port, with 2 Serial Ports

Posted 25 April 2016 - 06:05 AM

LOL! Using the word "streamline" to try to describe a process that involves Excel is a joke.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2