Results 1 to 6 of 6

Thread: save data from hyperterminal into mysql through vb.net

  1. #1
    Join Date
    Aug 2008
    Location
    malaysia
    Posts
    31
    Rep Power
    0

    save data from hyperterminal into mysql through vb.net

    Hi,

    I just want to get some idea on where to start.
    I have successfully receive SMS data from hyperterminal and i can display them in vb.net textbox.

    The problem is i want to save the data in mysql.
    I have the way to save data to mysql through vb.net. But i don't know how to capture the incoming data from hyperterminal and pass it to mysql.

    Code:
    +CMT: "+601xxxxxxxx",,"08/12/17,11:37:27+32"
    Receive msg
    I want to pass the phone number, receive date and time, and the receive message to mysql. How to take the info i want and ignoring other.

    Any suggestion will be appreciate.Thanks!

  2. #2
    Join Date
    Mar 2008
    Location
    pd
    Posts
    497
    Rep Power
    90
    You'll have to parse the line you read. You could do it a character at a time, or if the format is fairly fixed, you can look for field delimiters in the string. I don't remember names of VB functions, so your code will look something like:

    Code:
    lineFromPhone = readPhone();
    if (left$(lineFromPhone, 6) == "+CMT: \"")
    {
      delim = "\"";
      numberStart = instr(lineFromPhone, delim) + 1;
      // then search from last position - note extra argument
      numberEnd = instr(lineFromPhone, delim, numberStart) - 1;
      receiveTimeStart = instr(lineFromPhone, delim, numberEnd + 2) + 1;
      receiveTimeEnd = instr(lineFromPhone, delim, receiveTimeStart) - 1;
      // if you've got all the delimiters, the line is probably good
      // if you haven't, there's something wrong with it - maybe 
      // more than one format available?
      number = mid$(lineFromPhone, numberStart, numberEnd);
      receiveTime = mid$(lineFromPhone, receiveTimeStart, receiveTimeEnd);
    }
    else
      debug("mangled: " + lineFromPhone);
    That should get you what you want, but I doubt I've got the function names right. If the fields were very reliably delimited, you may be able to strip off the first and last quote and 'split' the string on '","' - that's the way I'd do it in Java. If the format isn't very consistent, you've no choice but to make some good guesses (like by hunting the quotes in the code above), and extracting the data by ranges. You should carefully validate data you get this way, just in case you've made a bad assumption in your guesses.

  3. #3
    Join Date
    Aug 2008
    Location
    malaysia
    Posts
    31
    Rep Power
    0
    I got your idea and i can get the data which i want.

    However, i will not always get the SMS in the hyperterminal.
    If let say, i have opened the hp port from vb.net.
    Then i execute the command that use to take the data from hp. It got error because by the time i executed it. My hp terminal hasn't get any data yet. It means i have't receive any SMS yet.

    Hence, it can't do the command :
    if i detect +CMT then it will start taking the data.

  4. #4
    Join Date
    Mar 2008
    Location
    pd
    Posts
    497
    Rep Power
    90
    Are you doing something like:

    Code:
    // wait for CMT:
    the String = serialPort.readLine();
    if (theString.equals("+CMT"))
    {
      theMessage = serialPort.readLine();
      // and theMessage is empty, or the readLine blocks because
      // because you've 'missed' the message?
    }
    I'm not a high-level I/O guru, but I can write code like this too! If this is what you're doing, then the problem is that the I/O port is unbuffered (is what I've decided in my mind, there might be a better explanation). The SMS message continues to be output in between your code reading the +CMT and the next readLine, where you expect to read it.
    What I typically do in these situations is to run a port reader in a separate thread with its own buffer. All the thread does is wait in a blocking read on the port, writing any bytes it receives to an internal buffer. The thread exposes an interface that allows programs to read port input from the thread's internal buffer.

    If you can write a program that just copies input from the handphone to the console like:

    Code:
    // help I can't write VB!
    String s;
    while ((s = serialPort.readLine()) != null)
      System.out.println(s);
    ... and it reliably captures all the +CMT output, then you could try the reader thread with its own buffer.

    Just thought: usually I do this with raw ports, but you're using a Serial Port control of some kind, aren't you? Can you use flow control to get what you want?
    Last edited by Seanie; 23-12-2008 at 12:32 PM. Reason: flow control?

  5. #5
    Join Date
    Aug 2008
    Location
    malaysia
    Posts
    31
    Rep Power
    0
    I take the data from hp and put them on the textbox. Then i command vb.net to take the data from the textbox and process them.

    That is my plan. But i don't have idea what command to use in vb.net, so it can execute the process every time it detect the new incoming data display in the textbox.

    If i put an additional button. After i get the data then i will click this button to execute the process. Then the it is working.

    Can you use flow control to get what you want?
    Yes, vb.net combine the the flow control to take data in serialport.

  6. #6
    Join Date
    Mar 2008
    Location
    pd
    Posts
    497
    Rep Power
    90
    A long time since I programmed in VB - I guess you've written an application which is a single form? In the 'load' function of the form, you should be able to start another thread that can update your text box. Just search for "threads in vb.net" and you'll get something useful. You may need to pass a reference to your text box to the new thread (I can't remember how secure namespaces are in VB). Alternatively, you may be able to do start your project(?) with a module function, instead of the form, as the start point. Then you could start threads before loading the form.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How PHP and MySQL helped voter data analysis
    By saengch in forum Showcase
    Replies: 1
    Last Post: 16-01-2009, 05:47 PM
  2. How do i fix data truncated error in mysql?
    By silentD in forum Website Programming
    Replies: 3
    Last Post: 14-01-2008, 03:19 PM
  3. How do i display data from mysql database?
    By silentD in forum Website Programming
    Replies: 2
    Last Post: 14-01-2008, 10:16 AM
  4. problem import data drpd ms excel ke MySQL
    By mys_az in forum Website Programming
    Replies: 6
    Last Post: 20-09-2007, 11:54 AM
  5. Export hugh data from MySQL
    By Kongtechnology in forum Website Programming
    Replies: 3
    Last Post: 16-07-2007, 04:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

SEO by vBSEO 3.5.0 RC1 PL1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110