java program

Discussion in 'Programmer's Corner' started by vishnumoorthy, May 1, 2011.

  1. vishnumoorthy

    Thread Starter New Member

    May 1, 2011
    1
    0
    hi...
    i have c# program, i need this code in java, please help me...... the c# program is as follows..
    using System;
    using System.IO.Ports;
    using System.Threading;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    namespace Test_MCP3201_Serial
    {
    classProgram
    {
    staticvoid Main(string[] args)
    {

    constdouble VREF = 5.00;

    int b = 0x4000, k = 0;



    SerialPort serialPort1 = newSerialPort("COM1", 9600, Parity.None, 8, StopBits.One);



    serialPort1.Open();

    // Reading the data from ADC MCP3201

    serialPort1.RtsEnable = true; // CLK goes low
    serialPort1.DtrEnable = false; // CS goes high

    // CS goes low allowing the conversion process to be started
    serialPort1.DtrEnable = true;

    // Processing all 15 CLK pulses
    for (int i = 0; i < 15; i++)
    {
    // CLK goes low
    serialPort1.RtsEnable = true;
    // Reading appropriate bit into variable b
    if (serialPort1.CtsHolding == false) k |= b;

    // shift bits of the variable b right to check the next bit
    b = b >> 1;
    // CLK goes high
    serialPort1.RtsEnable = false;
    }
    // Conversion is done, so CS line goes high
    serialPort1.DtrEnable = false;

    // Closing the serial porter
    serialPort1.Close();

    // We need only lower 12 bits of the binary result
    k = k & 0xFFF;

    // Now the variable k contains the binary result of the conversion.
    // The value of k must be transformed into float value which will be
    // saved in variable total
    int binRes = k;
    double total = Convert.ToDouble(binRes);

    // Calculating the final result
    total = VREF / 4096 * total;

    // Outputting the data on to screen
    Console.WriteLine("ADC result: {0}", total);
    }
    }
     
  2. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
  3. arnavkumar

    New Member

    Oct 30, 2013
    4
    0
    I am also sorry i cant change this code into Java code as i do not know anything about C#...
     
  4. WBahn

    Moderator

    Mar 31, 2012
    17,715
    4,788
    But he gave you a link to a translator that would do the conversion for you. Assuming the translator does a good job, why would you have to know anything about C#?
     
  5. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    This thread is over two years old. I don´t see any purpose in replying to it, or even trying to translate said code over again. Is this some kind of school assignment?
    If you got some own code that you need to translate, why don´t you make your own thread?
     
  6. sirch2

    Well-Known Member

    Jan 21, 2013
    1,008
    351
    There are around 20 lines of actual code there and they would appear to be well commented, just code it. C# syntax is pretty similar to Java so the basics should not present a problem. For the serial port see javax.comm.SerialPort and /or google "Java Serial Port"
     
  7. WBahn

    Moderator

    Mar 31, 2012
    17,715
    4,788
    Good observation. I assumed the response I was replying to came from the OP.
     
  8. arnavkumar

    New Member

    Oct 30, 2013
    4
    0
    Sorry for doing this stupid thing, as i am new with the forum so i will take care of its in future.
     
Loading...